多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# 图片无缝滚动插件 ## Jquery 插件 >[danger]使用该插件前首先需要引入jquery ~~~ (function($){ $.fn.jcMarquee = function(options) { var defaults = { 'marquee':'x', 'margin_bottom':'0', 'margin_right':'0', 'speed':'10' }; var options = $.extend(defaults,options); return this.each(function() { var $marquee = $(this), $marquee_scroll = $marquee.children('ul'); $marquee_scroll.append("<li class='clone'>"+"</li>"); $marquee_scroll.find('li').eq(0).children().clone().appendTo('.clone'); var $marquee_left = $marquee_scroll.find('li'); if (options.marquee == 'x') { var x = 0; $marquee_scroll.css('width','1000%'); $marquee_left.find('div').css({'margin-right':options.margin_right}); $marquee_left.css({'margin-right':options.margin_right}); function Marquee_x(){ $marquee.scrollLeft(++x); _margin = parseInt($marquee_left.find('div').css('margin-right')); if(x==$marquee_left.width()+_margin) { x = 0 }; }; var MyMar=setInterval(Marquee_x,options.speed); $marquee.hover(function(){ clearInterval(MyMar); },function(){ MyMar=setInterval(Marquee_x,options.speed); }); } if (options.marquee == 'y') { var y = 0; $marquee_scroll.css('height','1000%'); $marquee_left.find('div').css('margin-bottom',options.margin_bottom); $marquee_left.css('margin-bottom',options.margin_bottom); function Marquee_y(){ $marquee.scrollTop(++y); _margin = parseInt($marquee_left.find('div').css('margin-bottom')); if(y==$marquee_left.height()+_margin) { y = 0 }; }; var MyMar=setInterval(Marquee_y,options.speed); $marquee.hover(function(){ clearInterval(MyMar); },function(){ MyMar=setInterval(Marquee_y,options.speed); }); }; }); }; })(jQuery) ~~~ ## 用法 ### 1.引入插件 ### 2. html部分 >[danger]可根据实际情况进行调整 ~~~ <div id="Marquee_x"> <ul> <li> <div><img height="150" width="128" src="http://localhost:63342/html/images/ad.jpg" alt="图片1"/></div> <div><img height="150" width="128" src="http://localhost:63342/html/images/ad.jpg" alt="图片2"/></div> <div><img height="150" width="128" src="http://localhost:63342/html/images/ad.jpg" alt="图片3"/></div> <div><img height="150" width="128" src="http://localhost:63342/html/images/ad.jpg" alt="图片4"/></div> <div><img height="128" width="128" src="http://localhost:63342/html/images/ad.jpg" alt="图片5" /></div> <div><img height="128" width="128" src="http://localhost:63342/html/images/ad.jpg" alt="图片6"/></div> </li> </ul> </div> ~~~ ### 3. CSS代码 >[success]根据实际情况进行调整 ~~~ ul,li{list-style:none} #Marquee_x { overflow:hidden; width: 580px; } //定义容器宽度 #Marquee_x ul li ,#Marquee_x ul li div{ float:left;} #Marquee_y { overflow:hidden; height:500px; width:200px; } ~~~ ### 4. 调用插件 ~~~ <script> $(function(){ //水平滚动 $('#Marquee_x').jcMarquee({ 'marquee':'x','margin_right':'10px','speed':1 }); //垂直滚动 $('#Marquee_y').jcMarquee({ 'marquee':'y','margin_bottom':'10px','speed':5 }); }); </script> ~~~