HTML
<ul class="container" >
<li class="default-state">
some stuff
</li>
</ul>
SASS
.default-state
transition: all 0.2s ease 0s
width: 20px
.new-state
width: 100px
JS
$itemClone = $('li.default-state').clone();
$('ul').append($itemClone);
$itemClone.addClass('new-state');
What's happening is the div appears in the list with its class already as '.new-state', and no transition is applied.
What I find absurd is when I do this:
$itemClone = $('li.default-state').clone();
$('ul.container').append($itemClone);
setTimeout(function(){
$itemClone.addClass('new-state');
}, 1);
It works perfectly. But I feel like using .delay() or setTimeout should be unnecessary in this scenario.
I know.append()
doesn't have a callback function, is there another jquery method that I could add to this to avoid adding stupid 1ms delays?
I want to keep all my transitions/animations in SASS because the widths are dynamic on media queries.