Comments (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.
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.
This set method would be also nice to change the animation target while the animation is running
from anime.
Related Issues (20)
- begin() and complete() with loop: true on timelines are only called once HOT 3
- get continues position (x,y) from moving SVG object HOT 2
- Anyway to add static value for properties css via anime function? HOT 2
- timeline doesn't loop anything added with add() HOT 1
- Mixing CSS units not working in ['from', 'to'] scenario
- SUSPEND ON VISIBILITY CHANGE demo seems not right HOT 4
- Search bar in documentation. HOT 4
- A dedicated section for setup and installation guide. HOT 3
- if use translate and scale for the same time,it will be strange HOT 1
- changeComplete is not called when a big lag happens at the very start
- JAVASCRIPT Nested OBJECT HOT 1
- Animation does not continue after pause and reversal HOT 2
- Speed up the duration during reverse playback
- Unable to use anime.js with node and express HOT 11
- Feature: ability to set innerHTML beyond numeric values HOT 1
- Spider-weeb app
- Bug report: spring-based motion not completing (Vanilla JS, HTML, CSS) HOT 4
- How to run animation on same element but with different text ? HOT 3
- can you run a for each loop in the targets? or refresh where the target is pointing to with the loopComplete callback?
- Just a question about line drawing in the docs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anime.