让我的动画在悬停时触发播放。我把所有的东西都准备好了,但是当我试图再次悬停去玩的时候,似乎什么都没有用。
你知道我写错了什么吗?
var squares = document.getElementById("test");
var animation = bodymovin.loadAnimation({
container: test,
renderer: "svg",
loop: false,
autoplay: false,
path: "https://dl.dropboxusercontent.com/BodyMovin/squares.json"
});
squares.addEventListener("mouseenter", function () {
animation.play();
});
function playAnim(anim, loop) {
if(anim.isPaused) {
anim.loop = loop;
anim.goToAndPlay(0);
}
}
function pauseAnim(anim) {
if (!anim.isPaused) {
anim.loop = false;
}
}发布于 2017-10-29 08:58:40
当动画到达它的最后一帧时,它不会回到第一帧。这就是为什么如果你调用play,什么都不会发生,因为它已经结束了,没有更多的东西可以玩了。
您应该执行以下操作:
squares.addEventListener("mouseenter", function () {
animation.goToAndPlay(0);
});如果你只想让它在到达最后一帧时重放,这应该是可行的:
var isComplete = true;
svgContainer.addEventListener('mouseenter', function(){
if(isComplete){
squares.goToAndPlay(0);
isComplete = false;
}
})
squares.addEventListener('complete', function(){
isComplete = true;
})发布于 2017-10-27 19:00:22
虽然我对Bodymovin (和Lottie)的经验只来自React Native world,但我还是要尝试一下。
这应该是非常直接的停止动画,并在光标离开元素时重新启动它:
squares.addEventListener("mouseenter", function () {
animation.play();
});
squares.addEventListener("mouseleave", function () {
animation.gotoAndStop(0);
});https://stackoverflow.com/questions/45490901
复制相似问题