Hi there! I'm trying to play my animation on "mouseover" event and reverse back to frame 0 on "onmouseout" event. Here's my code.
var myAnim = bodymovin.loadAnimation({
wrapper: menuButton, // the dom element that will contain the animation
animationData: animData,
animType: 'svg',
loop: false,
prerender: false,
autoplay: false,
rendererSettings: {
progressiveLoad: false,
//path: the relative path to the animation object. (animationData and path are mutually exclusive. because our bodymovin data is already here, we do not need to include)
}
});
menuButton.onmouseover = function(e) { // sets up the on-click function
myAnim.playSegments([myAnim.currentFrame, 20], true)
}
menuButton.onmouseout = function(e) { // sets up the on-click function
myAnim.playSegments([myAnim.currentFrame, 0], true)
}
But it looks like the animation start playing every time I'm moving the mouse inside the DOM.
What I'm doing wrong?
Hi !
I had the exact same issue so here is the answer I found :
var curFrame;
container.addEventListener('mouseenter', fLaunch);
function fLaunch() {
container.removeEventListener('mouseenter', fLaunch);
anim.playSegments([curFrame,20], true);
logoAnim.addEventListener('mouseleave', fReverse);
anim.onEnterFrame = fSaveFrame;
}
function fReverse() {
container.removeEventListener('mouseleave', fReverse);
anim.playSegments([curFrame,0], false);
container.addEventListener('mouseenter', fLaunch);
anim.onEnterFrame = fSaveFrame;
}
function fSaveFrame() {
curFrame = anim.currentFrame;
}
Hope this will help :)
Seb
Will try that @sebvct14
@ghosper if I understand correctly, the problem is because mouseover on html triggers when navigating nested children of your main element.
you can do a couple of things to solve it, depending on your specific case:
I'm trying to do something similar.
I exported a single animation that includes both the mouseenter animation and the mouseleave animation, which are different.
I'm trying to set up that their would be no jump/cut, if user leaves before Enter animation is finished , or (re)Enter before Leave animation is finished. Instead it would either play the bits backwards or towards "middle" (which is one frame, the hover state, paused, between the 2 animations).
I managed a bit but somehow since "currentFrame" is applying on segments and not over the whole animation, it doesn't work.
Help is greatly appreciated!
Codepen is here:
https://codepen.io/Eklor/project/editor/AVjWBM?fbclid=IwAR0oi0ePWqJIlSBduW3Yr0HVgVxcsFM1aKl0rjqxvYhTpdO0wi2wxzscSXA#
PS: I start coding in JS with this project so be gentle :). I haven't coded since AS2...
Most helpful comment
I'm trying to do something similar.
I exported a single animation that includes both the mouseenter animation and the mouseleave animation, which are different.
I'm trying to set up that their would be no jump/cut, if user leaves before Enter animation is finished , or (re)Enter before Leave animation is finished. Instead it would either play the bits backwards or towards "middle" (which is one frame, the hover state, paused, between the 2 animations).
I managed a bit but somehow since "currentFrame" is applying on segments and not over the whole animation, it doesn't work.
Help is greatly appreciated!
Codepen is here:
https://codepen.io/Eklor/project/editor/AVjWBM?fbclid=IwAR0oi0ePWqJIlSBduW3Yr0HVgVxcsFM1aKl0rjqxvYhTpdO0wi2wxzscSXA#
PS: I start coding in JS with this project so be gentle :). I haven't coded since AS2...