可能是 jQuery.delay Bug?

发布于 2024-10-26 20:28:29 字数 832 浏览 7 评论 0原文

我将 jQuery.delay 与 jQuery.accordion 和 jQuery.fadeIn/Out 效果结合使用。这是我的 javascript:

<script type="text/javascript">
  $(function() {
    $("#accordion").load("update.php");
    var refresh = setInterval(function() {
      $("#accordion").fadeOut("slow", function() {
        $("#accordion").load("update.php", function() {
          $("#accordion").delay(1);
          $("#accordion").fadeIn("slow");
        });
      });
    }, 5000);
  });
</script>

它的作用是在手风琴布局中加载 update.php 生成的 HTML(即它是可折叠内容),并且每 5 秒它将轮询 update.php 以获取新 HTML,并在淡出旧 HTML 后将其淡入。

问题出现在 $("#accordion").delay(1); 行。有了这一行,可折叠的内容部分就会以某种方式被缩减,并且不会像适当的手风琴效果那样“展开”。所有数据都还在;您可以单击并拖动鼠标向下滚动。它只是无法在浏览器中正确呈现或正确绘制 div 之类的。通过简单地删除该行,它就可以成功加载并且没有问题。

我鼓励您尝试重现我的结果,并让我知道您是否可以找到解决方法,因为我确实需要那里的延迟!感谢您的阅读。

I'm using jQuery.delay in tandem with jQuery.accordion and jQuery.fadeIn/Out effects. Here is my javascript:

<script type="text/javascript">
  $(function() {
    $("#accordion").load("update.php");
    var refresh = setInterval(function() {
      $("#accordion").fadeOut("slow", function() {
        $("#accordion").load("update.php", function() {
          $("#accordion").delay(1);
          $("#accordion").fadeIn("slow");
        });
      });
    }, 5000);
  });
</script>

What this does is load HTML generated by update.php in an accordion layout (i.e it's collapsible content), and every 5 seconds it will poll update.php for new HTML and fade it in after fading out the old HTML.

The problem arises at the line reading $("#accordion").delay(1);. With this line in, the section of content that's collapsible gets curtailed somehow and won't "unfurl" like a proper accordion effect should. All the data is still there; you can click and drag your mouse to scroll down through it. It just doesn't render properly in the browser or draw the div correctly or something. By simply removing that line, it loads successfully and without issue.

I encourage you to try reproducing my results, and let me know if you can locate a work-around, because I really do need that delay in there! Thank you for reading.

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

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

发布评论

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

评论(3

悲歌长辞 2024-11-02 20:28:29

delay() 不能替代 setTimeout()。它延迟运行动画,但没有动画运行(淡出应该已经完成​​)

delay() is no replacement for setTimeout(). It delayes running animations, but there is no animation running(fadeOut should already be finished there)

少女七分熟 2024-11-02 20:28:29

如果您想延迟淡入淡出,您的代码应为:

          $("#accordion").delay(1).fadeIn("slow");

请参阅: http://jsfiddle.net/Jaybles/ Vf97G/

If you are trying to delay the fade, your code should read:

          $("#accordion").delay(1).fadeIn("slow");

See: http://jsfiddle.net/Jaybles/Vf97G/

各自安好 2024-11-02 20:28:29

和所有事情一样,我是个白痴。事实证明,jQuery 的开发者一直都知道这个问题,并通过 autoHeight 和clearStyles 进行编程来解决这个问题。如果其他人在使用 AJAX 手风琴效果时遇到类似的 div 截断错误,您将需要使用这些参数之一来纠正它。它与delay() 与fade() 效果交互以创建0 高度元素的方式有关。 autoHeight 将它们的高度重置为最高元素,而clearStyles 在事件上完全重置它们。

As with all things, I am an idiot. It turns out the makers of jQuery knew of this issue all along and programmed in autoHeight and clearStyles to fix the issue. If anyone else is encountering a similar div truncation error with their AJAX'd accordion effect, you will want to use one of these parameters to rectify it. It had to do with the way delay() interacted with fade() effects to create 0 height elements. autoHeight resets the height of them to your tallest element, and clearStyles resets them entirely on an event.

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