不想要的“闪烁”在jQuery中使用隐藏和显示时的效果 [英] unwanted "flickering" effect when using hide and show in jquery

查看:830
本文介绍了不想要的“闪烁”在jQuery中使用隐藏和显示时的效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在某些div上使用jQueryshow和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?

推荐答案

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

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>

尝试在CSS中添加display:none:

Try adding display:none in the CSS:

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

即使允许JavaScript操作它,CSS也会应用于DOM,所以如果您这样做,当你加载页面时,应该没有闪烁。

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.

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

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.

这篇关于不想要的“闪烁”在jQuery中使用隐藏和显示时的效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆