javascript - 可否帮我看看轮播出现了什么问题?
怪我咯
怪我咯 2017-04-11 11:27:32
[JavaScript讨论组]

仿照slide.js的传送带效果,最后效果在下面网站有:

http://yoo.bilibili.com/html/blog/index.htm

自己尝试实现同样效果,可是出现了定时器不受控制的情况,附上全部代码,望高手们能帮我看看哪里有问题?谢谢!




    
    
    Document
    
    


    

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(1)
天蓬老师

function callbackN(){

        var delay=setTimeout(function(){
       if(transitioned){
         if(index==itemNum+1){
        index=1;
        $('.carousel .listBox').css({transition:'transform 1ms ease 0s',transform:'translate3d(0px,0px,0px)'});
        $('.carousel .item.active').removeClass('active').siblings($('.carousel .item')).eq(2).addClass('active')
    }      
   // $('.playPrev').on('click',function(){clearInterval(loop);playPrev(callbackP)});
   // $('.playNext').on('click',function(){clearInterval(loop);playNext(callbackN)});  
   //loop=setInterval(function(){playNext(callbackN)},1000);
       }
},501);            

}
function playNext(callback){


if(index<=itemNum)
    {   
        $('.carousel .listBox').css('transition','transform 500ms ease 0s');
        $('.carousel .item.active').removeClass('active').next($('carousel .item')).addClass('active');
        index++;}
        var transformArray= $('.carousel .listBox').css('transform'),
            translateArray=transformArray.split(','),
            translate=parseInt(translateArray[4]); 
        console.log(index,translate);  
        $('.carousel .listBox').css('transform','translate3d(' + (translate - 1000) + 'px, 0px, 0px)');
        callback()

}
function callbackP(){

        var delay=setTimeout(function(){
        if(index==0)
        {
            index=5;
            $('.carousel .listBox').css({transition:'transform 0s ease 0s',transform:'translate3d(-4000px,0px,0px)'});
            $('.carousel .item.active').removeClass('active').siblings($('.carousel .item')).eq(5).addClass('active');
        }
  //  $('.playPrev').on('click',function(){clearInterval(loop);playPrev(callbackP)});
   // $('.playNext').on('click',function(){clearInterval(loop);playNext(callbackN)});  
  //loop=setInterval(function(){playNext(callbackN)},1000);
    },501);

}

function playPrev(callback){

      
   if(index>=1)
  {   $('.carousel .listBox').css('transition','transform 500ms ease 0s'); 
      $('.carousel .item.active').removeClass('active').prev($('carousel .item')).addClass('active');
       var transformArray= $('.carousel .listBox').css('transform'),
              translateArray=transformArray.split(','),
              translate=parseInt(translateArray[4]); 
          console.log(index,translate);  
      $('.carousel .listBox').css('transform','translate3d(' + (translate+1000) + 'px, 0px, 0px)');
      index--}
      callback()

}

$('.playNext').off().on('click',function(){
   // $('.playPrev').off('click');
  //  $('.playNext').off('click');
    clearInterval(loop);
    playNext(callbackN);
    loop=setInterval(function(){playNext(callbackN)},1000);
    
})
$('.playPrev').off().on('click',function(){
    //$('.playPrev').off('click');
   // $('.playNext').off('click');
    clearInterval(loop);
    playPrev(callbackP);
    loop=setInterval(function(){playNext(callbackN)},1000);
})
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号