【问题标题】:how to remove all slides from jquery cycle 2 slider如何从 jquery 循环 2 滑块中删除所有幻灯片
【发布时间】:2015-03-19 22:30:17
【问题描述】:

我想从 JQuery 2 循环滑块中删除所有幻灯片,在 API 它说要删除特定幻灯片,您可以运行此代码:

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

但是我怎样才能全部删除呢?

【问题讨论】:

  • 不能$('.cycle-slideshow').find('.cycle-slide').remove();
  • 我可以,但我想当我想再次添加幻灯片时它会搞砸
  • 那么在这种情况下,我猜你可以简单地在从0slideCount 的循环中调用remove。您应该能够从hash 获得slideCount。代码看起来像for(var i = 0; i < slideCount; i++) { $('.cycle-slideshow').cycle('remove', i); }
  • 我也试过了,但它没有删除名为 .cycle-sentinel 的幻灯片,我猜它是为连续循环复制的幻灯片。

标签: jquery jquery-plugins jquery-cycle2


【解决方案1】:

您可以使用循环删除所有幻灯片。从0slideCount 循环调用remove:

// 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');

【讨论】:

  • 这是对的,但您也需要重新启动滑块。
  • @user1937021 - 一个问题,您是否能够在不使用$('.cycle-slideshow .cycle-slide').eq(slide).remove(); 的情况下实现这一目标?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多