I was wondering what JQuery actually does to a <div>
when you set it to hide?
Does it simply set it's CSS display style to none?
The reason i ask, i wanted to set a <div>
to be hidden initially (by setting the property manually, not by cal开发者_如何学Goling .hide) then use .show() to bring it into view when needed.
It sets it to display: none
, though some extra work comes on, that's the overall effect.
If you have a <div style="display: none;">
then .show()
will show it :)
Here's a quick demo showing this
If you're more curious as to exactly what happens, you can always look directly at the source :) The .hide()
function inner-workings can be seen here: http://github.com/jquery/jquery/blob/master/src/effects.js#L59
The main difference between .hide()
/.show()
and .css('display':'whatever')
for example, is that .show()
restores the previous display
value (or clears it so it's default if it was never hidden with .hide()
), instead of just picking a new one :)
According to the JQuery API with speed set to none, yes
Otherwise when it will do the following (also from the API documentation):
When a duration is provided, .hide() becomes an animation method.
The .hide() method animates the width, height, and opacity of the
matched elements simultaneously. When these properties reach 0,
the display style property is set to none to ensure that the element
no longer affects the layout of the page.
.hide() applies display:none to the element's style.
Does it simply set it's CSS display style to none?
Yes, that's what it does eg it sets:
display: none;
精彩评论