I'm using Twitter Bootstrap and I notice that jQuery show()
or fadeIn()
doesn't make DOM element marked with class hidden
appear because the jQuery functions only remove the display: none
specification. However, the visibility
is still set to hidden
.
I wonder what is the best possible way to work around this?
hidden
class on the elementIn particular, I want to know whether fixing this with jQuery or css is better and why.
The optional speed parameter specifies the speed of the hiding/showing, and can take the following values: "slow", "fast", or milliseconds. The optional callback parameter is a function to be executed after the hide() or show() method completes (you will learn more about callback functions in a later chapter).
jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.
You need to make sure the target div has an ID. Bootstrap has a class "collapse", this will hide your block by default. If you want your div to be collapsible AND be shown by default you need to add "in" class to the collapse. Otherwise the toggle behavior will not work properly.
The visibility: hidden rule, on the other hand, hides an element, but the element will still take up space on the web page. If you want to hide an element but keep that element's space on the web page, using the visibility: hidden; rule is best.
The css class you're looking for is .collapse
. This sets the element to display: none;
So using $('#myelement').show()
will work properly.
UPDATE : Bootstrap v3.3.6 has updated .collapse back to:
.collapse { display: none; }
This will fade your invisible element in and remove the class
$('#element.hidden').css('visibility','visible').hide().fadeIn().removeClass('hidden');
http://jsfiddle.net/7qxVL/
If you don't really need the element to be invisible (ie take up the space) tho you might wanna redefine .hidden (in you local css, don't change bootstrap source, or even better, in your local LESS file).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With