The visibility
does not allow animation, or is visible or not. But you can do this with the opacity
. In that case the best is to let the CSS do it and not the animate()
jQuery.
You can do it like this:
CSS:
#escondida {
opacity: 0;
transition: opacity 1s;
}
.mostrar {
opacity: 1 !important;
}
Javascript:
$("button").click(function () {
var $el = $("#escondida");
$el.addClass('mostrar');
setTimeout(function () {
$el.removeClass('mostrar');
}, 1000);
});
Code adds the class mostrar
when the button is clicked, activating the transition
1 second via CSS. At the end of 1 second (1000 milliseconds) Javascript removes the class by starting new animation via CSS, now for opacity 0
.
Man, for God’s sake, because my addClass isn’t working, man, I’m cracking my head already, I’ve tried everything and it won’t... I already got your code on top copied and pasted , I did other examples, but it’s not working, puts q saco... http://pastebin.com/1fqt8LM7
– Gabriel Longatti
@Gabriellongatti but in this Pastebin you don’t use my code. Where’s the CSS I put together in the answer? It works well: https://jsbin.com/nupewunebe/edit?html,output
– Sergio