当在jquery中使用隐藏和显示时不想要的“闪烁”效果(unwanted “flickering” effect when using hide and show in jquery)

编程入门 行业动态 更新时间:2024-10-22 21:33:50
当在jquery中使用隐藏和显示时不想要的“闪烁”效果(unwanted “flickering” effect when using hide and show in jquery)

当在某些div上使用jQuery“show”和“hide”时,Firefox中出现令人讨厌的“闪烁”效果。 任何想法,当这可能发生?

I'm getting an annoying "flickering" effect in Firefox when using jQuery "show" and "hide" on some div's. Any idea when this could be happening?

最满意答案

取决于你闪烁的意思(如果它只在页面加载时闪烁),而不是:

$(document).ready(function(){ $("hide").hide(); }); <div id="hide">My Hidden Text</div>

尝试在CSS中添加display:none:

<div id="hide" style="display:none">My Hidden Text</a>

CSS甚至在JavaScript允许操纵之前就被应用到DOM,所以如果你这样做,当你加载页面时不应该有闪烁。

另外值得注意的是,在Firefox中,当你改变窗口的大小(垂直),并且当前的滚动位置接近或者在窗口的底部时,有一个错误会导致窗口闪烁。

Depending on what you mean by flicker (if it only flickers when the page loads), instead of doing:

$(document).ready(function(){ $("hide").hide(); }); <div id="hide">My Hidden Text</div>

Try adding display:none in the CSS:

<div id="hide" style="display:none">My Hidden Text</a>

CSS is applied to the DOM before even JavaScript is allowed to manipulate it, so if you do this, there should be no flicker when you load the page.

Also of note, in Firefox, there is a bug that causes the window to flicker when you change the size of the window (vertically), and the current scroll position is close or at the bottom of the window.

更多推荐

本文发布于:2023-07-26 15:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:效果   unwanted   jquery   flickering   show

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!