Is there a better way of triggering css3 transitions than this, I think this is a little hacky or is this the way everyone is doing this?
Lets say we got a div with the following css:
.box{
position: fixed;
top: 50%;
left: 50%;
margin: -50px 0px 0px -50px;
width: 100px;
opacity: 0;
transition: opacity .3s ease-out;
}
.box.box-visible{
opacity: 1;
}
Now we got the following jQuery:
$(function(){
$('.box').addClass('box-visible');
});
This doesn’t trigger the animation so when we do this:
$(function(){
var transition = setTimeout(function(){
$('.box').addClass('box-visible');
}, 1);
});
Then the transition is triggered, but isn’t this a bit hacky? Is there another solution?
Thanks for reading I hope my answer was clear.
You just have to modify your code a little……
Then in Jquery
Remember: either set the height of the div or put some text within it to notice the change.