js 实现banner轮播

矫情吗;* 2022-08-22 14:13 327阅读 0赞
  1. <!--Banner Start-->
  2. <div id="Banner">
  3. <ul id="fcimg">
  4. <{section name=ad_k loop=$adData }>
  5. <a <{if $adData[ad_k].url }> href="<{$adData[ad_k].url}>" target="_blank"<{/if}> >
  6. <!-- <li class="list-item" style="background: url(<{$smarty.const.UPYUN_WWW_PATH}><{$adData[ad_k].image}>) no-repeat center top;"></li> -->
  7. <li class="" style="background: url(<{$smarty.const.UPYUN_WWW_PATH}><{$adData[ad_k].image}>) no-repeat center top;"></li>
  8. </a>
  9. <{/section}>
  10. </ul>
  11. <script type="text/javascript" src="js/duice.js"></script>
  12. </div>

js:

  1. var indx = 1;
  2. var looper = 6000;
  3. var myTimer;
  4. $(document).ready(function(){
  5. if($('#thscrll') && $('#thscrll img').length > 0) {
  6. $('#thscrll').css({"padding-bottom":"15px"}); }
  7. if($("#fcimg li").length >1){
  8. $("#fcimg").after( $('<div></div><ul id="fcnum"></ul>'));
  9. for(i=1;i<=$("#fcimg li").length;i++){
  10. if(i==1) $("#fcnum").append($("<li class=\"crn\"> </li>"));
  11. else $("#fcnum").append($("<li> </li>"));
  12. }
  13. myTimer = setInterval('showFImg("#fcimg li","#fcnum li","crn")', looper);
  14. $("#fcnum li").click(function(){
  15. indx = $("#fcnum li").index(this);
  16. showFImg("#fcimg li","#fcnum li","crn");
  17. try{
  18. clearInterval(myTimer);
  19. myTimer = setInterval('showFImg("#fcimg li","#fcnum li","crn")', looper);
  20. }catch(e){}
  21. return false;
  22. });
  23. $("#fcimg").hover(function(){
  24. if(myTimer){ clearInterval(myTimer); }
  25. },function(){
  26. myTimer = setInterval('showFImg("#fcimg li","#fcnum li","crn")', looper);
  27. });
  28. }
  29. });
  30. function showFImg(il,nl,cs){
  31. if($(il).length >1){
  32. crobj = $(il).eq(indx);
  33. $(il).not(crobj).hide();
  34. $(nl).removeClass(cs)
  35. $(nl).eq(indx).addClass(cs);
  36. crobj.stop(true,true).fadeIn('slow');
  37. indx = (++indx) % ($(il).length);
  38. }
  39. }

发表评论

表情:
评论列表 (有 0 条评论,327人围观)

还没有评论,来说两句吧...

相关阅读

    相关 banner广告实现

    1.广告轮播的实现     今天呢,我给大家分享一下广告轮播的一些值得注意的地方。  1>首页,创建一个Ad广告bean,把要在图片上显示的属性全定义在Ad中,上代码: