jquery圖片輪播切換

jquery圖片輪播切換

使用方法


js

$(function(){

                var slideBox=$(".slideBox");
                var ul =slideBox.find("ul");
                var oneWidth=slideBox.find("ul li").eq(0).width();
                var num=slideBox.find(".spanBox span");
                var length=$(".slideBox ul li").length;
                var length02=$(".slideBox ul li").length-1;

                var timer=null;
                var sw=0;

                //每個span綁定click事件,完成切換顏色和動畫,以及讀取參數值
                num.on("click",function(){

                    sw=$(this).index();
                    ul.animate({
                        "right":oneWidth*sw
                    });
                   $(".spanBox span").removeClass("active");                    
                   $(".spanBox span").eq(sw).addClass("active");
                });
                //左右按鈕的控制效果
                $(".prev").click(function(){
                    clearInterval(timer);
                    sw++;

                    if(sw>length02)
                    {

                        sw=length02;
                    }

                    ul.animate({

                        "right":oneWidth*sw
                    });
                     $(".spanBox span").removeClass("active");

                  $(".spanBox span").eq(sw).addClass("active");

                });
                $(".next").click(function(){
                    clearInterval(timer);
                    sw--;

                    if(sw<0)
                    {

                        sw=0;
                    }

                    ul.animate({

                        "right":oneWidth*sw
                    });
                   $(".spanBox span").removeClass("active");

                  $(".spanBox span").eq(sw).addClass("active");
                });
                 //定時器的使用,自動開始
                timer = setInterval(function (){

                sw++;
                if(sw==length){sw=0};
                num.eq(sw).trigger("click");
                },2000);
                //選中是去除定時器
                $(".slideBox").hover(function(){

                clearInterval(timer);
                },function(){

                timer = setInterval(function (){
                sw++;
                if(sw==num.length){sw=0};
                num.eq(sw).trigger("click");
                },2000);
                    })
            });

本插件的原理不過是加載js以後往頁面裏插入幾個節點,非常簡單,使用者可以修改源碼來獲得自己想要的效果

預覽地址:http://www.jquery66.com/demos/js/j70/index.html
下載鏈接:https://u18725144.ctfile.com/fs/18725144-330281670

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章