• 常见的js图片或内轮换效果


    CSS:

    .CommentCustom{ height:210px; margin:30px 0;}
    .CommentCustom .scrollWrap{ position:relative; height:170px;}
    .CommentCustom .scrollWrap span.btn{ position:absolute; cursor:pointer; display:block; width:10px; height:122px; background:url(../images/cssPos/custom_last_bg.jpg) no-repeat left top;}
    .CommentCustom .scrollWrap span.btnLeft{ left:0; top:0; background-position:left top;}
    .CommentCustom .scrollWrap span.btnLeft:hover{ background-position:left -123px;}
    .CommentCustom .scrollWrap span.btnRight{ right:0; top:0; background-position:-10px top;}
    .CommentCustom .scrollWrap span.btnRight:hover{ background-position:-10px -123px;}
    .CommentCustom .scrollWrap .scrollMain{ position:relative;z-index:1;width:930px; height:170px; margin:0 auto; overflow:hidden;}
    .CommentCustom .scrollWrap .scrollMain ol{ position:absolute; left:0; top:0;}
    .CommentCustom .scrollWrap .scrollMain ol li{height:170px; float:left; width:930px;}
    .CommentCustom .btnItem{ width:80px; margin:0 auto; margin-top:10px;}
    .CommentCustom .btnItem li{ float:left;_display:inline; margin:0 3px;width:20px; height:20px; cursor:pointer; text-align:center; line-height:20px; font-weight:bold; color:#fff; background:url(../images/cssPos/custom_last_bg.jpg) no-repeat -40px -82px;}
    .CommentCustom .btnItem li.selected{ background-position:-20px -82px;}

    DOM:

    <div class="CommentCustom" data-param='{
                                                    "mouseType":"click",
                                                    "slideType":"dirLeft",
                                                    "speed":"normal",
                                                    "easing":"easeInExpo"
                                                    }'>
                <div class="scrollWrap">
                    <span class="btn btnLeft"></span>
                    <span class="btn btnRight"></span>
                    <div class="scrollMain">
                        <ol class="clearfix">
                            <li><img src="images/c1.jpg" /></li>
                            <li><img src="images/c2.jpg" /></li>
                            <li><img src="images/c1.jpg" /></li>
                            <li><img src="images/c2.jpg" /></li>
                            <li><img src="images/c1.jpg" /></li>
                            <li><img src="images/c2.jpg" /></li>
                        </ol>
                    </div>
                </div>
                <ul class="btnItem clearfix">
                    <li class="selected">1</li>
                    <li>2</li>
                    <li>3</li>
                    <li>4</li>
                    <li>5</li>
                    <li>6</li>
                </ul>
            </div>

    JS:

    function CustomComment(obj){
            /**
            @mouseType:[mouseover||click]  执行幻灯片的鼠标事件
            @slideType:[scrollLeft||scrollTop||dirLeft||dirTop||fadeIn]  幻灯片的效果
            @speed:[fast||normal||sleew||5]
            @easing:["def"||"easeInQuad"||"easeOutQuad"||"easeInOutQuad"||"easeInCubic"||
                 "easeOutCubic"||"easeInOutCubic"||"easeInQuart"||"easeOutQuart"||
                 "easeInOutQuart"||"easeInQuint"||"easeOutQuint"||"easeInOutQuint"||
                 "easeInSine"||"easeOutSine"||"easeInOutSine"||"easeInExpo"||
                 "*easeOutExpo"||"*easeInOutExpo"||"easeInCirc"||"easeOutCirc"||"easeInOutCirc"||
                 "easeInElastic"||"easeOutElastic"||"easeInOutElastic"||"easeInBack"||"easeOutBack"||
                 "easeInOutBack"||"easeInBounce"||"easeOutBounce"||"easeInOutBounce"]          幻灯片执行的动画方式
            @autoPlay:"true,5"  自动播放的时间
            
            */
            this.CustomComment=$(obj);//保存一个幻灯片
            this.scroll=$("ol",this.CustomComment);//保存幻灯片对象
            this.scrollMainWidth=this.scroll.children().eq(0).width();
            this.scrollMainHeight=this.scroll.children().eq(0).height();
            this.scrollWrap=$(".scrollWrap",this.CustomComment);
            this.btnItems=$(".btnItem li",this.CustomComment);//保存按钮序列
            this.btnLeft=$(".btnLeft",this.CustomComment);//保存左边的按钮
            this.btnRight=$(".btnRight",this.CustomComment);//保存右边的按钮
            this.data=$.parseJSON(this.CustomComment.attr("data-param"));//保存幻灯片参数
            this.data.mouseType=this.data.mouseType||"mouseover";//初始化鼠标默认事件
            this.data.slideType=this.data.slideType||"scrollLeft";//初始化幻灯片样式
            this.data.speed=Number(this.data.speed)*1000||this.data.speed||"normal";//初始化执行幻灯片的时间
            this.data.autoPlay=this.data.autoPlay||false;//初始化自动执行
            this.btnItems.parent().width(this.btnItems.length*26+"px");
            if(this.data.slideType=="scrollLeft"){
                this.scroll.width(this.scrollMainWidth*this.scroll.children("li").length+"px");
                }else if(this.data.slideType=="scrollTop"){
                    this.scroll.children().css("float","none");
                    }else if(this.data.slideType=="dirLeft"||this.data.slideType=="dirRight"||this.data.slideType=="dirTop"||this.data.slideType=="dirBootom"){
                        this.def=0;
                        this.scroll.children("li").css({
                                                   float:"none",
                                                   position:"absolute",
                                                   display:"none"
                                                   }).eq(0).show();;
                        };
            var _this_=this;
            this.t=null;
            this.loop=0;
            this.btnItems.bind(this.data.mouseType,function(){
                                                    var i=$(this).index();
                                                    _this_.loop=i;
                                                    switch(_this_.data.slideType){
                                                        case "scrollLeft":
                                                                _this_.scrollLeft(i);
                                                                break;
                                                        case "scrollTop":
                                                                _this_.scrollTop(i);
                                                                break;
                                                        case "fadeIn":
                                                                _this_.fadeIn(i);
                                                                break;
                                                        case "dirLeft":
                                                                if(i>_this_.def){
                                                                    _this_.dirLeft(i);
                                                                    _this_.def=i;
                                                                    }else if(i<_this_.def){
                                                                        _this_.dirRight(i);
                                                                        _this_.def=i;
                                                                        };
                                                                break;
                                                        case "dirTop":
                                                                if(i>_this_.def){
                                                                        _this_.dirTop(i);
                                                                        _this_.def=i;
                                                                    }else if(i<_this_.def){
                                                                        _this_.dirBottom(i);
                                                                        _this_.def=i;
                                                                        };
                                                                break;
                                                        default:
                                                                _this_.fadeIn(i);
                                                        };
                                                    });
            this.btnLeft.click(function(){
                                        _this_.loop--;
                                        if(this.loop<0||_this_.loop<-_this_.btnItems.length){
                                            _this_.loop=_this_.btnItems.length-1;
                                            };
                                        _this_.btnItems.eq(_this_.loop).trigger(_this_.data.mouseType);
                                    });
            this.btnRight.click(function(){
                                        _this_.loop++;
                                        if(_this_.loop>=_this_.btnItems.length){
                                            _this_.loop=0;
                                            };
                                        _this_.btnItems.eq(_this_.loop).trigger(_this_.data.mouseType);        
                                    });
            if(this.data.autoPlay[0]){//设置是否自动播放
                this.autoPlay();
                this.scrollWrap.mouseover(function(){window.clearInterval(_this_.t);}).mouseout(function(){_this_.autoPlay();});
                };
            };
        CustomComment.prototype={
            scrollLeft:function(i){
                    this.scroll.stop().animate({left:-i*this.scrollMainWidth+"px"},this.data.speed,this.data.easing||"swing");
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                },
            scrollTop:function(i){
                    this.scroll.stop().animate({top:-i*this.scrollMainHeight+"px"},this.data.speed,this.data.easing||"swing");
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                },
            fadeIn:function(i){
                    this.scroll.children("li").hide().eq(i).fadeIn(this.data.speed,this.data.easing||"swing");
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                },
            dirLeft:function(i){
                    var _this_=this;
                    if(this.btnItems.eq(i).is(".selected")){return;}
                    this.scroll.children("li").eq(i).css({
                                                         left:this.scrollMainWidth+"px",
                                                         display:"block"
                                                         });
                    this.scroll.animate({left:-this.scrollMainWidth+"px"},this.data.speed,this.data.easing||"swing",function(){
                                                                                                   $(this).css("left",0);
                                                                                                  _this_.scroll.children("li").eq(i).css("left",0).siblings().hide();
                                                                                                   });
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                
                },    
            dirRight:function(i){
                    var _this_=this;
                    if(this.btnItems.eq(i).is(".selected")){return;}
                    this.scroll.children("li").eq(i).css({
                                                         left:-this.scrollMainWidth+"px",
                                                         display:"block"
                                                         });
                    this.scroll.animate({left:this.scrollMainWidth+"px"},this.data.speed,this.data.easing||"swing",function(){
                                                                                                   $(this).css("left",0);
                                                                                                  _this_.scroll.children("li").eq(i).css("left",0).siblings().hide();
                                                                                                   });
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                },
            dirTop:function(i){
                    var _this_=this;
                    if(this.btnItems.eq(i).is(".selected")){return;}
                    this.scroll.children("li").eq(i).css({
                                                         top:this.scrollMainHeight+"px",
                                                         display:"block"
                                                         });
                    this.scroll.animate({top:-this.scrollMainHeight+"px"},this.data.speed,this.data.easing||"swing",function(){
                                                                                                   $(this).css("top",0);
                                                                                                  _this_.scroll.children("li").eq(i).css("top",0).siblings().hide();
                                                                                                   });
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                },
            dirBottom:function(i){
                    var _this_=this;
                    if(this.btnItems.eq(i).is(".selected")){return;}
                    this.scroll.children("li").eq(i).css({
                                                         top:-this.scrollMainHeight+"px",
                                                         display:"block"
                                                         });
                    this.scroll.animate({top:this.scrollMainHeight+"px"},this.data.speed,this.data.easing||"swing",function(){
                                                                                                   $(this).css("top",0);
                                                                                                  _this_.scroll.children("li").eq(i).css("top",0).siblings().hide();
                                                                                                   });
                    this.btnItems.eq(i).addClass("selected").siblings().removeClass("selected");
                },
            autoPlay:function(){
                    var _this_=this;
                this.t=window.setInterval(function(){
                                                   _this_.btnRight.click();
                                                   },Number(this.data.autoPlay[1])*1000);
                }
            };
        CustomComment.init=function(CustomComments){
                var _this=this;
                CustomComments.each(function(){
                                      new _this(this);
                                      });
            };

    此插件调用方式,模仿淘宝给各个商家提供的插件,直接在dom结构中传参数调用。此插件可配合easing.js动画缓动插件传参数实现丰富的效果!

    注释:

    本人在开发过程中,难免会出现各种bug,单基本实用与主流浏览器,希望朋友们多多测试!欢迎你的各种建议!

  • 相关阅读:
    Entity Framework 二
    Entity Framework 一
    Leetcode练习(Python):动态规划类:第221题:最大正方形:在一个由 0 和 1 组成的二维矩阵内,找到只包含 1 的最大正方形,并返回其面积。
    Leetcode练习(Python):动态规划类:第139题:单词拆分:给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。
    Leetcode练习(Python):动态规划类:第95题:不同的二叉搜索树 II:给定一个整数 n,生成所有由 1 ... n 为节点所组成的二叉搜索树。
    Leetcode练习(Python):动态规划类:第96题:不同的二叉搜索树:给定一个整数 n,求以 1 ... n 为节点组成的二叉搜索树有多少种?
    机器学习案例二:缺失时间序列数据填补与ESN(回声状态网络)
    Leetcode练习(Python):动态规划类:第213题:打家劫舍 II:你是一个专业的小偷,计划偷窃沿街的房屋,每间房内都藏有一定的现金。这个地方所有的房屋都围成一圈,这意味着第一个房屋和最后一个房屋是紧挨着的。同时,相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。
    Leetcode练习(Python):动态规划类:第198题:打家劫舍:你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你在不触动警报装置的情况下,能够偷窃到的最高金额。
    Leetcode练习(Python):动态规划类:第70题:爬楼梯:假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数。
  • 原文地址:https://www.cnblogs.com/yangliulang/p/2716457.html
Copyright © 2020-2023  润新知