move.js icon indicating copy to clipboard operation
move.js copied to clipboard

No animation with div elements created via Javascript.

Open CaudellDev opened this issue 10 years ago • 5 comments

When I create a div element with HTML and use move functions on it, it works just fine. However, when I use Javascript to create and element ( = document.createElement('div')), and set the class and Id, it won't animate with the move functions. It just jumps to the end position, even if I have the duration set.

CaudellDev avatar Nov 06 '14 20:11 CaudellDev

Anyone else have this problem? I don't want to rely on only pre-defined divs, it would be much easier if I could make divs on the fly and animate them as well.

CaudellDev avatar Nov 06 '14 21:11 CaudellDev

I think I'm having the same issue. A hack I found that worked(though is obviously not what I want to keep around in my code) was to wrap the animation in a setTimeout with a wait of 1ms.

var anim = function() {
    move(elem)
             .set('left','120px')
             .duration(700)
             .end();
}
setTimeout(anim, 1);

mdgriffith avatar Nov 12 '14 18:11 mdgriffith

I'm also experiencing this same issue and the workaround suggested by @mdgriffith is also working, although not ideal.

garethfoote avatar Dec 02 '14 12:12 garethfoote

+1

ben-eb avatar Dec 02 '14 16:12 ben-eb

It looks like the important part is forcing the layout, or waiting until its done automatically

After creating the element, requesting a property from it that requires a layout, like elem.clientHeight, should do the trick, though still a bit hackish.

http://stackoverflow.com/questions/12088819/css-transitions-on-new-elements

mdgriffith avatar Dec 03 '14 20:12 mdgriffith