The issue:
I am facing a challenge with an HTML element that has a class called hidden
which hides the element with the css attribute display: none;
. When I use JavaScript to remove the class, the element immediately becomes visible again (the original display
property is restored). What I would like to achieve is to have a smooth animation when the element becomes visible again, similar to how it can be done with jQuery using $('.hidden').show(1000)
or $('.hidden').fadeIn(1500)
. I attempted to use .animate()
in conjunction with removing the class, but it did not produce the desired effect.
The conditions
- It is important not to interfere with the inline CSS properties of the element (especially avoiding setting
display: block
) - The behavior should resemble that of jQueryUI's removeClass method: http://jqueryui.com/removeClass/
The inquiry:
Is there a way to animate the changes (with a duration > 0) when I remove or alter the class of the HTML element?
The code:
CSS:
.hidden{
display: none;
}
HTML
<div class="hidden"> Lorem ipsum </div>
JS
$('.hidden').removeClass('hidden')