//----------定义幻灯片类 (function () { $.fn.slideshow = function (speed,autohei) { return this.each(function (i) { var curr = 0, child_size = $(this).find('li').size(), firstli = $(this).find('li:first').html(), autoplay = true, millisec = 4000,/*自动播放间隔*/ _this = $(this); if(autohei=='true'){ _this.append('
'+firstli+'
'); } /*添加按钮*/ if(child_size>1){ var btn = "
"; $(this).append(btn); } /*上一页按钮*/ $(this).find('.prev').click(function() { todo = curr-1<0?child_size-1:curr-1; var currli = _this.find('li').eq(curr); var prevli = _this.find('li').eq(todo); currli.css({'z-index':1}).stop(true,false).animate({'left':'30%'},speed,function(){$(this).css('display','none')}); prevli.css({'z-index':2,'display':'block','left':'-100%'}).stop(true,false).animate({'left':'0'},speed); curr = todo; }); /*下一页按钮*/ $(this).find('.next').click(function() { todo = (curr + 1) % child_size; var currli = _this.find('li').eq(curr); var nextli = _this.find('li').eq(todo); currli.css({'z-index':2}).stop(true,false).animate({'left':'-100%'},speed,function(){$(this).css('display','none')}); nextli.css({'z-index':1,'display':'block','left':'30%'}).stop(true,false).animate({'left':'0'},speed); curr = todo; }); /*自动播*/ auto_play = setinterval(function() { if(autoplay && child_size>0){ _this.find('.next').click(); } },millisec); $(this).hover(function() { autoplay = false; },function() { autoplay = true; }) }); }; })(jquery); /*----------滚动----------*/ (function () { $.fn.roll = function (speed,btn_left,btn_right,auto) { return this.each(function (i) { var boxwidth,liwidth,lisize, childul = $(this).children('ul'), stopplay = false, _this = $(this); var ulcont = childul.html(); childul.append(ulcont); function getparameter(){ lisize = _this.find('li').size(); boxwidth = _this.innerwidth(); liwidth = _this.find('li:first').outerwidth(true); ulwidth = lisize/2*liwidth; childul.css('width',liwidth*lisize); } getparameter(); $(window).resize(function(){ getparameter(); }); $(btn_left).click(function(){ childul.stop(true,true); targetleft = parseint(childul.css('left'))+liwidth; if(targetleft>=liwidth){ childul.css('left',ulwidth*-1); } childul.animate({left : '+='+liwidth},speed); }) $(btn_right).click(function(){ childul.stop(true,true); targetleft = parseint(childul.css('left'))-liwidth; if(targetleft < ulwidth*-1){ childul.css('left',0); } childul.animate({left : '-='+liwidth},speed); }) /*自动播*/ if(auto=="autoplay" && lisize>0){ autoplay = setinterval(function() { if(!stopplay){$(btn_right).click()}; },3500); _this.hover(function() { stopplay = true; },function() { stopplay = false; }) } }); }; })(jquery);