2015-03-19 48 views
1

我想删除从JQuery的2周期滑块滑动,在API它说,除去特定的幻灯片,你可以运行此代码:如何从jQuery的周期中的所有幻灯片2滑块

$('.cycle-slideshow').cycle('remove', 1); 

但如何我可以删除所有?

+0

你就不能'$( '循环播放幻灯片。 ')找到(' 循环幻灯片'。)删除();' – Cyclonecode 2015-03-19 11:47:46

+0

我所能。但是当我想再次添加幻灯片时,我认为它会把它弄糟。 – user1937021 2015-03-19 11:49:52

+0

那么在这种情况下,我想你可以简单地在从'0'到'slideCount'的循环中调用'remove'。你应该能够从'hash'中获得'slideCount'。代码看起来像'for(var i = 0; i Cyclonecode 2015-03-19 11:53:01

回答

2

您可以使用循环删除所有幻灯片。调用一个循环移除0slideCount

// get the number of slides 
var numSlides = $('.cycle-slideshow').data('cycle.opts').slideCount; 
for(var slide = 0; slide < numSlides; slide++) { 
    $('.cycle-slideshow').cycle('remove', slide); 
    // if the elements are not removed from the DOM you could also 
    // try call $('.cycle-slideshow .cycle-slide').eq(slide).remove(); here 
} 
// reinitialize the plugin 
$('.cycle-slideshow').cycle('reinit'); 
+0

这是正确的,但你也需要重新初始化滑块。 – user1937021 2015-03-19 13:50:11

+0

@ user1937021 - 我更新了我的答案。 – Cyclonecode 2015-03-19 14:30:27

+0

@ user1937021 - 一个问题,你能否在不使用'$('.cycle-slideshow.cycle-slide')的情况下实现这个功能。 – Cyclonecode 2015-03-21 07:44:39