简体   繁体   English

如何停止动画Javascript?

[英]how to stop animation Javascript?

When hovering over the menu, I want to trigger the animation. 将鼠标悬停在菜单上时,我想触发动画。 I want to stop it if the menu is no longer overflown. 如果菜单不再溢出,我想停止它。

CORRECTION 更正


     animeMiddle() {
            this.menu.addEventListener('mouseover', () => {
                  this.ctx = this.middle.animate([
                            {width: '0'},
                            {width: '100%'}
                        ],
                        {
                            duration: 1000, iterations: Infinity
                        })

            });
            this.menu.addEventListener('mouseout', () => {
                this.ctx.cancel();
            });
        }

Animation.pause() is what you need. 您需要Animation.pause()

From MDN: 从MDN:

The pause() method of the Web Animations API's Animation interface suspends playback of the animation. Web动画API的“动画”接口的pause()方法会暂停播放动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM