maccman / jquery.magicmove

Animate DOM transitions.

Home Page:http://maccman.github.io/jquery.magicmove/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swapping positions of elements works during animation, then reverts to original position.

EvanKnowles opened this issue · comments

Swapping the positions of two elements works during the animation. Immediately afterwards, when the elements are unfixed, they return to their original position (because their DOM positions haven't changed).

In the library-provided demo, using the following callback in magicMove will replicate this issue.

        let $sections = $(this).find('section');
        let i = Math.floor(($sections.length - 1) * Math.random());
        $($sections[i]).insertAfter($sections[i + 1]);

Actually calculating the swap seems harder - perhaps making the following change in the .done() of the magicMove function could be the easiest solution? It works for the provided example and this swapping example, happy to log a pull request if you're happy with it.

    return promise.done(function () {
        // make the DOM a mirror of the cloned DOM
        $el.html($clone.html());
        // Remove 'absolute' styles
        $unfix.call($el.find(options.selector));
    });