准备好在文档上调用hide()时闪烁 [英] Twinkling when call hide() on document ready
问题描述
当文档准备好在默认情况下具有display:block
和visibility:visible
的特定<div>
上时,我会调用hide()函数(我们默认显示它,并尝试使用jQuery隐藏它).
I call hide() function when document ready on a specific <div>
that has display:block
and visibility:visible
by default (we show it by default, and we try to hide it with jQuery).
有时,当我刷新页面时,<div>
会在不到一秒钟的时间内出现,然后根据hide()
功能消失.
Sometimes when I refresh the page the <div>
appears during a fraction of a second then disappears according to the hide()
function.
我的问题:有办法避免这种<div>
闪烁吗?
My question: is there a way to avoid this <div>
twinkling ?
谢谢
推荐答案
现在是渲染元素和执行JS代码之间的时间. 避免这种情况的方法不是将代码置于DOM-ready事件中,而是紧随元素之后:
It's the time between rendering the element and executing your JS code. The way to avoid this is not putting the code in the DOM-ready event but right after the element:
<div id="whatever">...</div>
<script>$('#whatever').hide();</div>
其他任何这样的注册事件处理程序当然仍然可以进入您的DOM就绪功能.
Anything else such a registering event handlers can still go into your DOM-ready function of course.
哦,您根本不需要使用visibility
-show()
和hide()
仍然只使用display
属性.
Oh, and you don't need to use visibility
at all - show()
and hide()
will only use the display
property anyway.
如果要隐藏的元素是请启用JavaScript"警告,请考虑使用<noscript>...</noscript>
-除非禁用JS,否则它将永远不会显示.
In case the element you want to hide is a "please enable JavaScript" warning, consider using <noscript>...</noscript>
- then it will never show up unless JS is disabled.
这篇关于准备好在文档上调用hide()时闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!