为什么我的循环幻灯片隐藏了所有幻灯片?

发布于 2024-12-17 04:22:56 字数 1703 浏览 1 评论 0原文

jQuery 插件 cycle 查找类 slideshow 的元素。我想将此类添加到

    元素中,以利用其
  • 制作幻灯片。但是,当我将 slideshow 类添加到
      元素时,所有
    • 消失,并且我没有看到任何幻灯片。

HTML 如下所示:

<ul>
  <li>
    <h3 class="expander">...</h3>
    <div class="content">
      <p>...</p>
      <h4>...</h4>
      <ul class="slideshow">
        <li>...</li>
        <li>...</li>
      </ul>
    </div>
  </li>
  ...
</ul>

如您所见,幻灯片

    包含在另一个列表中。该父列表由标题组成,单击时会显示每个列表项的内容。当 DOM 准备好时,我以编程方式隐藏所有 .content。然后,我向 .expander 添加一个点击侦听器,以便它们可以显示隐藏的 .content

在这些 .contents 中,我有 .slideshow,它们使用循环插件循环浏览其列表项。

关于这一切的另一个奇怪的事情是,在我将标题转换为相关内容的切换之前,幻灯片显示效果非常好。事实上,当我向标题添加切换功能时,幻灯片不再可见。但是如果我拿走幻灯片放映类,它们就会再次可见。当然,它们不再具有幻灯片功能...

这是所有这一切的 javascript:

$(document).ready(function()
{
  var expanders = $('.expander');
  expanders.each(function()
  {
    $('.content', $(this).parent()).toggle();
    $(this).click(function()
    {
      $('.content', $(this).parent()).toggle("blind", {"easing":"easeInOutCirc"}, "normal");
    });
  });
  $('.slideshow').each(function() {
    var parent = $(this).parent();
    $(this).cycle(
    {
      fx: 'scrollHorz',
      easing: 'easeInOutCirc',
      timeout: 0,
      nowrap: 1
    });
  });
});

知道什么可能导致此问题吗?

The jQuery plugin cycle looks for elements of class slideshow. I want to add this class to a <ul> element to make a slideshow out of its <li>s. But when I add the slideshow class to the <ul> element, all <li> disappear and I get no slideshow whatsoever.

The HTML looks like this:

<ul>
  <li>
    <h3 class="expander">...</h3>
    <div class="content">
      <p>...</p>
      <h4>...</h4>
      <ul class="slideshow">
        <li>...</li>
        <li>...</li>
      </ul>
    </div>
  </li>
  ...
</ul>

As you see, the slideshow <ul> is included in another list. This parent list consists of headers which reveal the content of each list item on click. I am hiding all the .contents programmatically when the DOM is ready. Then, I add a click listener to the .expanders so they can show the hidden .contents.

It is inside these .contentss that I have .slideshows which use the cycle plugin to cycle through their list items.

The other weird thing about all this is that the slideshow's worked perfectly before I transformed my headers into toggles for their associated content. Indeed, when I added the toggle functionality to the headers, the slides are no longer visible. But then if I take away the slideshow class, they are visible again. Of course, they no longer have slideshow functionnality...

Here is the javascript for all this:

$(document).ready(function()
{
  var expanders = $('.expander');
  expanders.each(function()
  {
    $('.content', $(this).parent()).toggle();
    $(this).click(function()
    {
      $('.content', $(this).parent()).toggle("blind", {"easing":"easeInOutCirc"}, "normal");
    });
  });
  $('.slideshow').each(function() {
    var parent = $(this).parent();
    $(this).cycle(
    {
      fx: 'scrollHorz',
      easing: 'easeInOutCirc',
      timeout: 0,
      nowrap: 1
    });
  });
});

Any idea what could be causing this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2024-12-24 04:22:56

显然,我需要将循环代码移到切换代码上方,如下所示:

$(document).ready(function()
{
  $('.slideshow').each(function() {
    var parent = $(this).parent();
    $(this).cycle(
    {
      fx: 'scrollHorz',
      easing: 'easeInOutCirc',
      timeout: 0,
      nowrap: 1
    });
  });
  var expanders = $('.expander');
  expanders.each(function()
  {
    $('.content', $(this).parent()).toggle();
    $(this).click(function()
    {
      $('.content', $(this).parent()).toggle("blind", {"easing":"easeInOutCirc"}, "normal");
    });
  });
});

我不知道为什么会这样,所以更好的答案将不胜感激。

Apparently, I needed to move the cycle code above the toggle code, like this:

$(document).ready(function()
{
  $('.slideshow').each(function() {
    var parent = $(this).parent();
    $(this).cycle(
    {
      fx: 'scrollHorz',
      easing: 'easeInOutCirc',
      timeout: 0,
      nowrap: 1
    });
  });
  var expanders = $('.expander');
  expanders.each(function()
  {
    $('.content', $(this).parent()).toggle();
    $(this).click(function()
    {
      $('.content', $(this).parent()).toggle("blind", {"easing":"easeInOutCirc"}, "normal");
    });
  });
});

I don't know why this works though, so better answers would be appreciated.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文