Giter Site home page Giter Site logo

Comments (3)

juliangarnier avatar juliangarnier commented on May 3, 2024 3

Simply wrap your animation in a function, and make sure to remove the elements from anim before each call.

Like this:

function followCursor(e) {
  var targets = ['.blue', '.green'];
  anime.remove(targets)
  anime({
    targets: targets,
    translateX: e.pageX,
    translateY: e.pageY,
    delay: function(el, i) {
      return i * 80;
    }
  });
}

document.body.onclick = followCursor;

Live example: http://codepen.io/juliangarnier/pen/ozpGdd

from anime.

co-l avatar co-l commented on May 3, 2024 1

I found a way to do so, and I think it would have a lot of value to make it accessible in the public API.

Here is what I did:

startAnimation = anime({
    targets: myObj,
    x: targetX,
    y: targetY,
    duration: 500,
    easing: 'easeOutQuad'
})

With initial values for targetX and targetY (let's say its the position of the user mouse/finger)
I'm capable of altering those values with the following code

startAnimation.tweens[0].to.numbers = [newTargetX]
startAnimation.tweens[1].to.numbers = [newTargetY]

I'm not sure it's exactly following the proper easing function, but it clearly works visually speaking.

Hope this helps 👍

from anime.

jantimon avatar jantimon commented on May 3, 2024

This set method would be also nice to change the animation target while the animation is running

from anime.

Related Issues (20)

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.