当前位置:   article > 正文

jquery图片滚动效果插件SuperSlide1.2_jquery() .slide({ titonclassname

jquery() .slide({ titonclassname

使用方法:

1. 包含插件JS文件

<script type="text/javascript" src="jquery.SuperSlide.js"></script>

2.

  1. <!--jquery slide begin-->
  2. <div class="effect">
  3. <div class="leftLoop">
  4. <div class="hd">
  5. <a class="next"></a>
  6. <ul>
  7. <li>1</li>
  8. <li>2</li>
  9. <li>3</li>
  10. <li>4</li>
  11. <li>5</li>
  12. </ul>
  13. <a class="prev"></a>
  14. </div>
  15. <div class="bd">
  16. <ul class="picList">
  17. <li>
  18. content1
  19. </li>
  20. <li>
  21. content2
  22. </li>
  23. <li>
  24. content3
  25. </li>
  26. <li>
  27. content4
  28. </li>
  29. <li>
  30. content5
  31. </li>
  32. </ul>
  33. </div>
  34. <script type="text/javascript">jQuery(".leftLoop").slide({ mainCell:".bd ul",effect:"fade",vis:1,scroll:1,autoPlay:false});</script>
  35. </div>
  36. </div>
  37. <!--jquery slide end-->

jquery.SuperSlide.js代码如下:

  1. /* SuperSlide1.2 -- Copyright ©2012 大话主席
  2. */
  3. (function($){
  4. $.fn.slide=function(options){
  5. $.fn.slide.deflunt={
  6. effect : "fade", //效果 || fade:渐显; || top:上滚动;|| left:左滚动;|| topLoop:上循环滚动;|| leftLoop:左循环滚动;|| topMarquee:上无缝循环滚动;|| leftMarquee:左无缝循环滚动;
  7. autoPlay:"true", //自动运行
  8. delayTime : 500, //效果持续时间
  9. interTime : 2500,//自动运行间隔。当effect为无缝滚动的时候,相当于运行速度。
  10. defaultIndex : 0,//默认的当前位置索引。0是第一个
  11. titCell:".hd li",//导航元素
  12. mainCell:".bd",//内容元素的父层对象
  13. trigger: "mouseover",//触发方式 || mouseover:鼠标移过触发;|| click:鼠标点击触发;
  14. scroll:1,//每次滚动个数。
  15. vis:1,//visible,可视范围个数,当内容个数少于可视个数的时候,不执行效果。
  16. titOnClassName:"on",//当前位置自动增加的class名称
  17. autoPage:false,//系统自动分页,当为true时,titCell则为导航元素父层对象,同时系统会在titCell里面自动插入分页li元素(1.2版本新增)
  18. prevCell:".prev",//前一个按钮元素。
  19. nextCell:".next"//后一个按钮元素。
  20. };
  21. return this.each(function() {
  22. var opts = $.extend({},$.fn.slide.deflunt,options);
  23. var index=opts.defaultIndex;
  24. var prevBtn = $(opts.prevCell, $(this));
  25. var nextBtn = $(opts.nextCell, $(this));
  26. var navObj = $(opts.titCell, $(this));//导航子元素结合
  27. var navObjSize = navObj.size();
  28. var conBox = $(opts.mainCell , $(this));//内容元素父层对象
  29. var conBoxSize=conBox.children().size();
  30. var slideH=0;
  31. var slideW=0;
  32. var selfW=0;
  33. var selfH=0;
  34. var autoPlay = opts.autoPlay;
  35. var inter=null;//setInterval名称
  36. var oldIndex = index;
  37. if(conBoxSize<opts.vis) return; //当内容个数少于可视个数,不执行效果。
  38. //处理分页
  39. if( navObjSize==0 )navObjSize=conBoxSize;
  40. if( opts.autoPage ){
  41. var tempS = conBoxSize-opts.vis;
  42. navObjSize=1+parseInt(tempS%opts.scroll!=0?(tempS/opts.scroll+1):(tempS/opts.scroll));
  43. navObj.html("");
  44. for( var i=0; i<navObjSize; i++ ){ navObj.append("<li>"+(i+1)+"</li>") }
  45. var navObj = $("li", navObj);//重置导航子元素对象
  46. }
  47. conBox.children().each(function(){ //取最大值
  48. if( $(this).width()>selfW ){ selfW=$(this).width(); slideW=$(this).outerWidth(true); }
  49. if( $(this).height()>selfH ){ selfH=$(this).height(); slideH=$(this).outerHeight(true); }
  50. });
  51. switch(opts.effect)
  52. {
  53. case "top": conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; height:'+opts.vis*slideH+'px"></div>').css( { "position":"relative","padding":"0","margin":"0"}).children().css( {"height":selfH} ); break;
  54. case "left": conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; width:'+opts.vis*slideW+'px"></div>').css( { "width":conBoxSize*slideW,"position":"relative","overflow":"hidden","padding":"0","margin":"0"}).children().css( {"float":"left","width":selfW} ); break;
  55. case "leftLoop":
  56. case "leftMarquee":
  57. conBox.children().clone().appendTo(conBox).clone().prependTo(conBox);
  58. conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; width:'+opts.vis*slideW+'px"></div>').css( { "width":conBoxSize*slideW*3,"position":"relative","overflow":"hidden","padding":"0","margin":"0","left":-conBoxSize*slideW}).children().css( {"float":"left","width":selfW} ); break;
  59. case "topLoop":
  60. case "topMarquee":
  61. conBox.children().clone().appendTo(conBox).clone().prependTo(conBox);
  62. conBox.wrap('<div class="tempWrap" style="overflow:hidden; position:relative; height:'+opts.vis*slideH+'px"></div>').css( { "height":conBoxSize*slideH*3,"position":"relative","padding":"0","margin":"0","top":-conBoxSize*slideH}).children().css( {"height":selfH} ); break;
  63. }
  64. //效果函数
  65. var doPlay=function(){
  66. switch(opts.effect)
  67. {
  68. case "fade": case "top": case "left": if ( index >= navObjSize) { index = 0; } else if( index < 0) { index = navObjSize-1; } break;
  69. case "leftMarquee":case "topMarquee": if ( index>= 2) { index=1; } else if( index<0) { index = 0; } break;
  70. case "leftLoop": case "topLoop":
  71. var tempNum = index - oldIndex;
  72. if( navObjSize>2 && tempNum==-(navObjSize-1) ) tempNum=1;
  73. if( navObjSize>2 && tempNum==(navObjSize-1) ) tempNum=-1;
  74. var scrollNum = Math.abs( tempNum*opts.scroll );
  75. if ( index >= navObjSize) { index = 0; } else if( index < 0) { index = navObjSize-1; }
  76. break;
  77. }
  78. switch (opts.effect)
  79. {
  80. case "fade":conBox.children().stop(true,true).eq(index).fadeIn(opts.delayTime).siblings().hide();break;
  81. case "top":conBox.stop(true,true).animate({"top":-index*opts.scroll*slideH},opts.delayTime);break;
  82. case "left":conBox.stop(true,true).animate({"left":-index*opts.scroll*slideW},opts.delayTime);break;
  83. case "leftLoop":
  84. if(tempNum<0 ){
  85. conBox.stop(true,true).animate({"left":-(conBoxSize-scrollNum )*slideW},opts.delayTime,function(){
  86. for(var i=0;i<scrollNum;i++){ conBox.children().last().prependTo(conBox); }
  87. conBox.css("left",-conBoxSize*slideW);
  88. });
  89. }
  90. else{
  91. conBox.stop(true,true).animate({"left":-( conBoxSize + scrollNum)*slideW},opts.delayTime,function(){
  92. for(var i=0;i<scrollNum;i++){ conBox.children().first().appendTo(conBox); }
  93. conBox.css("left",-conBoxSize*slideW);
  94. });
  95. }break;// leftLoop end
  96. case "topLoop":
  97. if(tempNum<0 ){
  98. conBox.stop(true,true).animate({"top":-(conBoxSize-scrollNum )*slideH},opts.delayTime,function(){
  99. for(var i=0;i<scrollNum;i++){ conBox.children().last().prependTo(conBox); }
  100. conBox.css("top",-conBoxSize*slideH);
  101. });
  102. }
  103. else{
  104. conBox.stop(true,true).animate({"top":-( conBoxSize + scrollNum)*slideH},opts.delayTime,function(){
  105. for(var i=0;i<scrollNum;i++){ conBox.children().first().appendTo(conBox); }
  106. conBox.css("top",-conBoxSize*slideH);
  107. });
  108. }break;//topLoop end
  109. case "leftMarquee":
  110. var tempLeft = conBox.css("left").replace("px","");
  111. if(index==0 ){
  112. conBox.animate({"left":++tempLeft},0,function(){
  113. if( conBox.css("left").replace("px","")>= 0){ for(var i=0;i<conBoxSize;i++){ conBox.children().last().prependTo(conBox); }conBox.css("left",-conBoxSize*slideW);}
  114. });
  115. }
  116. else{
  117. conBox.animate({"left":--tempLeft},0,function(){
  118. if( conBox.css("left").replace("px","")<= -conBoxSize*slideW*2){ for(var i=0;i<conBoxSize;i++){ conBox.children().first().appendTo(conBox); }conBox.css("left",-conBoxSize*slideW);}
  119. });
  120. }break;// leftMarquee end
  121. case "topMarquee":
  122. var tempTop = conBox.css("top").replace("px","");
  123. if(index==0 ){
  124. conBox.animate({"top":++tempTop},0,function(){
  125. if( conBox.css("top").replace("px","") >= 0){ for(var i=0;i<conBoxSize;i++){ conBox.children().last().prependTo(conBox); }conBox.css("top",-conBoxSize*slideH);}
  126. });
  127. }
  128. else{
  129. conBox.animate({"top":--tempTop},0,function(){
  130. if( conBox.css("top").replace("px","")<= -conBoxSize*slideH*2){ for(var i=0;i<conBoxSize;i++){ conBox.children().first().appendTo(conBox); }conBox.css("top",-conBoxSize*slideH);}
  131. });
  132. }break;// topMarquee end
  133. }//switch end
  134. navObj.removeClass(opts.titOnClassName).eq(index).addClass(opts.titOnClassName);
  135. oldIndex=index;
  136. };
  137. //初始化执行
  138. doPlay();
  139. //自动播放
  140. if (autoPlay) {
  141. if( opts.effect=="leftMarquee" || opts.effect=="topMarquee" ){
  142. index++; inter = setInterval(doPlay, opts.interTime);
  143. conBox.hover(function(){if(autoPlay){clearInterval(inter); }},function(){if(autoPlay){clearInterval(inter);inter = setInterval(doPlay, opts.interTime);}});
  144. }else{
  145. inter=setInterval(function(){index++; doPlay() }, opts.interTime);
  146. $(this).hover(function(){if(autoPlay){clearInterval(inter); }},function(){if(autoPlay){clearInterval(inter); inter=setInterval(function(){index++; doPlay() }, opts.interTime); }});
  147. }
  148. }
  149. //鼠标事件
  150. var mst;
  151. if(opts.trigger=="mouseover"){
  152. navObj.hover(function(){ clearTimeout(mst); index=navObj.index(this); mst = window.setTimeout(doPlay,200); }, function(){ if(!mst)clearTimeout(mst); });
  153. }else{ navObj.click(function(){index=navObj.index(this); doPlay(); }) }
  154. nextBtn.click(function(){ index++; doPlay(); });
  155. prevBtn.click(function(){ index--; doPlay(); });
  156. });//each End
  157. };//slide End
  158. })(jQuery);


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/120683
推荐阅读
相关标签
  

闽ICP备14008679号