jQuery SlideToggle 在 Firefox 中闪烁

发布于 2024-08-12 00:24:39 字数 409 浏览 7 评论 0原文

我遇到了 SlideToggle 的特殊情况,它会在 Firefox 中产生闪烁。

情况是当扩展元素比页面长并且 Firefox 中出现垂直滚动条时。

如果您向下滚动以阅读展开元素中的所有文本,然后单击触发器关闭该元素,Firefox 将闪烁一秒钟,然后页面重新调整并返回到展开元素展开之前的位置。 我尝试添加“return false;”无济于事。

这是一个测试页面,您可以在 FF 中看到点击关闭最后一个项目(Herbal Teas)时的效果: http://pollak-labs.com/clients/birthyourself/?page_id=21

I have a specific situation with slideToggle that creates a flicker in Firefox.

The situation was when the expanding element goes longer than the page and a vertical scrollbar appears in Firefox.

If you scroll down to read all of the text in the expanding element and then click on the trigger to close the element, Firefox would flash for a second and then the page readjusts and returns to its position before the expanded element was expanded.
I have tried adding ‘return false;’ to no avail.

Here's a test page where you can see the effect in FF when you click to close the last item (Herbal Teas): http://pollak-labs.com/clients/birthyourself/?page_id=21

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

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

发布评论

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

评论(3

走过海棠暮 2024-08-19 00:24:39

我认为发生这种情况的原因是因为通过项目向上滑动,页面高度变得越来越短。 Firefox 无法同时重绘页面、更改高度、向上滚动视口以及为元素设置动画。

这是我用来尝试解决问题的方法。潜在的副作用是,如果他们打开所有盒子并一一关闭它们,您将留下大量空白。但是,您不会关闭闪光灯。如果您滚动到页面的最底部,打开时也会遇到同样的问题。 $('html,body') 滚动行解决了以下问题:

$(".question").click(function(){
    var $animator = $(this).next(".answer"),
        $post     = $animator.closest('.post');
    if($animator.is(':visible')){
        $post.css('min-height', $post.height());
        $animator.slideUp("slow");
    } else {
        $('html, body').scrollTop($('html, body').scrollTop() - 1);
        $animator.slideDown("slow", function(){
            $post.css('min-height', 0);
        });
    }
});

I think the reason this is happening, is because by the item sliding up, the page height is getting shorter. Firefox can't redraw the page, change the height, scroll the viewport up, and animate your element all at the same time.

Here is what I would use to attempt to fix the problem. The potential side effect would be, if they opened all of the boxes and closed them one by one, you would be left with a lot of white space. However, you won't have the flashes on close. You also have the same problem on open if you are scrolled to the very bottom of the page. The $('html,body') scroll line addresses that:

$(".question").click(function(){
    var $animator = $(this).next(".answer"),
        $post     = $animator.closest('.post');
    if($animator.is(':visible')){
        $post.css('min-height', $post.height());
        $animator.slideUp("slow");
    } else {
        $('html, body').scrollTop($('html, body').scrollTop() - 1);
        $animator.slideDown("slow", function(){
            $post.css('min-height', 0);
        });
    }
});
音栖息无 2024-08-19 00:24:39

jQuery 试图同时做太多事情,而在这个过程中,它正在偷工减料,做非法的事情。例如,在获取元素的尺寸时,它实际上会更新它。这不是 FireFox 中的错误,而是 jQuery 中的错误。您可以在这里看到它:

Firefox:显示包含可滚动内容的隐藏元素会导致页面闪烁

当您学习时它,您会发现一些可能帮助您完全消除问题的事情,可能是通过覆盖 jQuery 行为。或者只是提交另一个错误:)

jQuery tries to do too many things at the same time, and in the process, it is cutting corners, doing illegal things. For example, while getting the dimensions of an element, it actually updates it. It is not a bug in FireFox, it is a bug in jQuery. You can see it here:

Firefox: Showing hidden Element containing scrollable Content causes Page Flicker

When you study it, you will discover a few things that might help you in eliminating your problem entirely, possibly by overriding jQuery behavior. Or just file another bug :)

墨落成白 2024-08-19 00:24:39

是的,Doug Neiner 的“hack”解决了我在 Firefox 和 IE6 中的闪烁问题,但在 Safari 中造成了另一个问题,所以我将其更改为:

$('html').scrollTop($('html').scrollTop()-1);

现在它在所有浏览器中都能完美运行。

Yes, Doug Neiner's "hack" solved my flicker problem in Firefox and IE6 but created another issue in Safari, so I have changed it to:

$('html').scrollTop($('html').scrollTop()-1);

Now it works perfectly in all browsers.

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