admin管理员组文章数量:1396802
I want to hide an element as soon as it bees visible (has loaded).
I have tried using timeout
and setInterval
. They work fine but they are a few seconds late. So first the element loads and then it disappears.
But I want it so it doesn't appear at all and just disappears without appearing first.
I tried to change the time and make it more/less but it didn't help. Is there another way?
I even tried to put the timeout and setinterval
inside window.load
it didn't work. I also tried checking when the element is visible by using the length but it was slow too.
window.setInterval(function(){
jQuery("#vz").find('div').first().hide();
}, 600);
I want to hide an element as soon as it bees visible (has loaded).
I have tried using timeout
and setInterval
. They work fine but they are a few seconds late. So first the element loads and then it disappears.
But I want it so it doesn't appear at all and just disappears without appearing first.
I tried to change the time and make it more/less but it didn't help. Is there another way?
I even tried to put the timeout and setinterval
inside window.load
it didn't work. I also tried checking when the element is visible by using the length but it was slow too.
window.setInterval(function(){
jQuery("#vz").find('div').first().hide();
}, 600);
Share
Improve this question
edited Dec 12, 2016 at 21:50
Fueled By Coffee
2,5697 gold badges32 silver badges44 bronze badges
asked Dec 12, 2016 at 20:47
sarahsarah
1571 gold badge3 silver badges11 bronze badges
8
- So what is making it visible, why are you using a timeout? – epascarello Commented Dec 12, 2016 at 20:48
- where is your html? – Ruhul Amin Commented Dec 12, 2016 at 20:49
-
Why not using a simple css rule for that? If you must use JS try to wrap your code in
$(document).ready()
– empiric Commented Dec 12, 2016 at 20:49 - I have some code given to me. it generates 2 of the same html elements with the same id. All i want to do is hide one of them. – sarah Commented Dec 12, 2016 at 20:50
- 1 So when are they generated? And the only way you will not get a flash of content is to hide it with CSS to start. Best solution, change whatever is making it twice.... – epascarello Commented Dec 12, 2016 at 20:54
1 Answer
Reset to default 6You can specify its visibility
as hidden
(In case you still want it to occupy space)
Or specify its display
as none
(In case you don't want it to occupy space)
Both of these should be done using CSS, so in your CSS file:
#vz {
//This:
visibility: hidden;
//Or this:
display: none;
}
And as a general role of thumb, initial style should be set in CSS and then you can animate/change it using JS or more CSS
本文标签: javascriptHow can I make an element disappearStack Overflow
版权声明:本文标题:javascript - How can I make an element disappear? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744144162a2592758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论