2012-06-03 25 views
0

我需要刷新div或jQuery函数后,从左列表中选择一个轮播从左列表中加载时滚动左滚动但功能执行时,下一个滚动停止。如何刷新jquery旋转木马自动播放

的代码是:

<script type="text/javascript"> 
    $(function() { 
    $('#carousel_1').carouFredSel({ 
     width: '100%', 
     auto: { 
     items: 1 
     }, 
     prev: '#prev1', 
     next: '#next1' 
    }); 

    $('#carousel_2').carouFredSel({ 
     width: '100%', 
     auto: { 
     items: 1 
     }, 
     prev: '#prev2', 
     next: '#next2' 
    }); 

    $('#carousel_3').carouFredSel({ 
     width: '100%', 
     auto: { 
     items: 1 
     }, 
     prev: '#prev3', 
     next: '#next3' 
    }); 

    var items = $('.list_switch>li>a').each(function() { 
     $(this).click(function() { 
     //remove previous class and add it to clicked tab 
     items.removeClass('current'); 
     $(this).addClass('current'); 

     //hide all content divs and show current one 
     $('.carousel').hide().eq(items.index($(this))).show('fast'); 
     }); 
    }); 

    // select the first tab on page load  
    items[0].click(); 
    }); 
</script> 

演示页:http://blogillucent.alwaysdata.net/aaa/coolcarousel.html

回答

0

可以使用play事件恢复所选滑块的滑动:

例如,

$("#foo").trigger("play"); 

请参阅文档here

你的代码,特别是:

var items = $('.list_switch>li>a').each(function() { 
    $(this).click(function() { 
    //remove previous class and add it to clicked tab 
    items.removeClass('current'); 
    $(this).addClass('current'); 

    //hide all content divs and show current one 
    $('.carousel').hide().eq(items.index($(this))).show('fast'); 

    // resume the slide on the selected slider 
    $('.carousel').eq(items.index($(this))).trigger("play"); 
    }); 
}); 

通过阅读文档,它应该暂停滑块,以使用play事件,所以你应该每个滑块初始化后,暂停的那些不可见:

例如,

$("#foo").trigger("pause"); 

您可以查看carouFredSel插件的Code examples for the custom events

+0

我没有注意到这个播放功能 - 它的工作原理!谢谢 – user743328

+0

@ user743328很高兴能帮到你! :)由于问题已解决,请勾选正确的答案以解决此问题_solved_! – Zuul