/** * Created by fanxiaojuan on 2017/6/27. */ $.fn.extend({ Carousel:function(elem,btnElem,opt,callback){ //$('#focus').Carousel('ul li','.focus-btn-box') if(!opt) var opt = {}; var index = 0, timer = null, time= opt.time?parseInt(opt.time,10):4000, speed = opt.speed?parseInt(opt.speed,10):600, list = this.find(elem), btn = $(btnElem).find('span'); if(timer){ clearInterval(timer); timer = null; } timer=setInterval(autoplay,time); function autoplay(){ index++; if(index >= list.length){ index = 0; } changeImg(index); } btn.click(function(){ clearInterval(timer); var _idx = $(this).index(); changeImg(_idx); }); btn.mouseover(function(){ clearInterval(timer); }); btn.mouseout(function(){ timer=setInterval(autoplay,time); }); function changeImg(cindex){ btn.slice(cindex,cindex+1).addClass('cur'); btn.slice(cindex,cindex+1).siblings().removeClass('cur'); list.slice(cindex,cindex+1).fadeIn(speed); list.slice(cindex,cindex+1).siblings().hide(); } }, Scroll:function(ele,father,opt,callback){ //参数初始化 if(!opt) var opt={}; var _this=this.find(ele).parents(father); var lineH=_this.find(ele+":first").height(), //获取行高 line=opt.line?parseInt(opt.line,10):parseInt(this.height()/lineH,10), //每次滚动的行数,默认为一屏,即父容器高度 speed=opt.speed?parseInt(opt.speed,10):800, //卷动速度,数值越大,速度越慢(毫秒) timer=opt.timer?parseInt(opt.timer,10):2000; //滚动的时间间隔(毫秒) if(line==0) line=1; var upHeight=0-line*lineH,timerID; //滚动函数 var scrollUp=function(){ _this.animate({ marginTop:upHeight },speed,function(){ for(i=1;i<=line;i++){ _this.find(ele+":first").appendTo(_this); } _this.css({marginTop:0}); }); }; //鼠标事件绑定 _this.hover(function(){ clearInterval(timerID); },function(){ timerID=setInterval(scrollUp,timer); }).mouseout(); }, Tab:function(ele, list ,opt, callback){ //参数初始化 if(!opt) var opt={}; var _this = this.find(ele); _this.click(function(){ var _idx = $(this).index(); var _list = $(this).parent().next().find(list).get(_idx); $(this).addClass('cur'); $(this).siblings().removeClass('cur'); $(_list).fadeIn(200); $(_list).siblings().hide(); }) } }); $(function(){ $('.totop').mouseenter(function(){ var w = $(document.body).width(); var y = $(this).offset().left; var _thisW = $('.totop-pic').width(); var r = w - y - _thisW - 3; $('.totop-pic').css('right',r + 'px'); $('.totop-pic').show(); }); $('.totop').mouseleave(function(){ $('.totop-pic').hide(); }); $('.totop').click(function(){ $(document.documentElement).animate({scrollTop:0},200); $(document.body).animate({scrollTop:0},200); }); })