I want to append an element to the DOM and then add a class with transition to apply a sliding effect. Currently I'm using setInterval()
with delay of 0
, otherwise transition won't happen (demo):
var $block = $('<div/>', {class: 'block'});
$('body').append($block);
setTimeout(function () {
$block.addClass('shifted');
}, 0);
I want to utilise jQuery.queue
instead, but with my current approach it doesn't work: appending the element and adding the class happen at once, so no transition is shown.
$('body')
.append($block)
.queue(function () {
$block.addClass('shifted');
});