New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete mojs-shapes from DOM on timeline Complete? #62
Comments
Hi Steven! Thanks a lot! Your demo looks awesome! Sorry for delayed reply. Adding/removing elements to/from DOM is bad for performance since every DOM change will trigger the chain of browser reorganizations and cleanups. So every time you will remove an element from the DOM it will trigger So const burst = new mojs.Burst({
// options
});
$(document.body).on('click', '.some-card', function (e) {
// reuse same burst by just tuning `x`/`y` of the burst to the current element's coordinates
burst
.tune({ x: e.pageX, y: e.pageY })
// replay it after tune
.replay()
}); Of course, since user can click on your cards frequently, with small delay, and you animations can overlap, you want to create a pool of bursts and increment pointer to current element in that pool on each click event, probably 5 would be enough to cover all your cards: codepen example I hope it sets more light over the problem. Please let me know if you have any further difficulties or if you have any thoughts. P.S. If you do want to remove the element from DOM after its done with it's job - just use onPlaybackComplete () {
$(this.el).remove();
} Of course, I won't suggest to proceed with this approach since it will cause DOM thrashing and will bother GC a lot. Cheers |
hey Oleg, Thanks for the good words, and for the detailed reply! Ah I see, I had a feeling there was a good reason for keeping things in the DOM. That makes a lot of sense, re:performance. For our prototyping, the Talk soon, |
Happy to help, please let me know if something you'll stumble upon something! 🎉 |
This was great to know, @legomushroom. Have you considered writing out an FAQ for something like this (or build one as we go along)? I'm sure more than a few of us will be creating thousands of animations for art projects and can always benefit from advice like this on how to manage performance. |
@darrentorpey thanks for the feedback. Yeah, we definitely need the |
Pure javascript implementation |
React js Component for context
In the current code, I can show an animation but the heart remains on the screen even though the animation has ended, is there a fix for this? Note: when the animation is fired again the heart is deleted and new animation is played, this is not an issue, the issue is again the next heart will remain on the screen. |
Hi @rajchandra3, As explained by @almgwary, you need to remove it by yourself as it is not implemented yet in the library. Use: const heart = new mojs.Shape({
left: 0,
top: 2,
shape: 'heart',
fill: '#E5214A',
scale: { 0: 2 },
easing: 'elastic.out',
duration: 1600,
delay: 300,
radius: 11,
onComplete: function() {
this.el.parentNode.removeChild(this.el);
}
}); 😉 |
Thanks, @xavierfoucrier for the quick response and making this clear. |
Hi Oleg,
Im excited to play with this library. Thanks for your work on it, and for the recent push on documentation, curve editor + player. These are AWESOME tools that I'm sure will push adoption.
I'm exploring this lib to draw shape fx for a web app. I'm already using
isShowEnd
to hide shapes generated, though considering so many will be generated in the life of a session (hours, even days in an open tab), it would be great to auto delete DOM elements created when each timeline completes.A couple of questions:
If I do something like:
I think I'm going to run into trouble, because animations overlap in time and I want each to complete before the deleting the shape[s] it makes.
Much appreciated!
~s
The text was updated successfully, but these errors were encountered: