Git Product home page Git Product logo

jquery.magicmove's Introduction

Magic Move

Animations and transitions are fairly crucial to the look and feel of modern applications, and can be a good way of indicating to a user what their interactions are doing. Indeed, the best interfaces have been clued up on this for a while now -- pretty much every interaction you have with iOS involves an animation.

However animations can get convoluted really fast, especially if you have a lot of different states which require different transitions depending on which states are being entered or left. This is a problem I've struggled with in more complex UIs, specifically figuring out the position of elements - (we ended up using position absolute for everything, and having a huge amount of conditional code).

I've always wondered if there's a better way of doing transitions and, rather than hard coding positions, delegate layout to the browser. Inspired by Keynote's Magic Move effect, I've made a little jQuery library to do transitions between DOM states.

$('.containers').magicMove({
    easing: 'ease',
    duration: 300
  },
  function(){
    var $el = $('<section>Third</section>');
    $(this).find('.second').after($el);
  }
);

The second argument to $.fn.magicMove is a callback, which gets executed in the context of whatever element you're transitioning. Simply manipulate the DOM, hide or show elements, add or remove classes, and the changes will be animated.

You can see an example of this in action on GitHub, notice that we're not calculating any position information--the browser is doing that for us.

The library works by appending a separate and hidden clone of the element you're transitioning to the page. Any DOM manipulation you do is actually manipulating that clone. Then, when you're finished, the library looks at the difference between the element's current position, and the clone's position, and animates between them (using CSS transitions).

jquery.magicmove's People

Contributors

maccman avatar p4bl1t0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery.magicmove's Issues

Removing an element leads to wrong animations

Not sure if this is a bug or if the library is not supposed to cover this specific use case but when I remove an element, this is what happens:

  1. All elements immediately jump back to the space available.
  2. Next, magicMove seems to kick in and animates the elements forward.
  3. Finally, the elements snap back to the correct position.

I'll make it clearer with this video.

license?

Hi! would love to use your package. What's the usage license?

Link to blog post/demo from repo?

Nice plugin, Alex. Can you add a link to the blog post and/or demo from the repo description and/or README file? I'm planning to feature this in my newsletter and I normally only include the direct link to the GH repo. I think it will help others sharing it, too. Thanks!

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

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));
    });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.