仅在鼠标悬停时播放精灵动画

Only playing Spritely animation on mouseover

本文关键字:播放 精灵 动画 悬停 鼠标      更新时间:2023-09-26

我目前正在使用Spritly在jQuery中创建一个动画。

我该如何在鼠标悬停时播放动画,然后在鼠标悬停后停止动画。。。

任何帮助都将是伟大的感谢,这是当前的代码:

(function($) {
            $('#booth').bind("mouseenter", function() {
                $('#phone').sprite({fps: 24, no_of_frames: 36})
                $(this).unbind();
            });
            $('#booth').bind("mouseout", function() {
                $(this).stop();
                $(this).unbind();
            });
        })(jQuery);

从Spritly文档来看,.spStop()似乎是您想要的方法:

        $('#booth').bind("mouseout", function() {
            $(this).spStop();
            $(this).unbind();
        });

我想您正在寻找.destroy()

制作您的代码:

$('#booth').bind("mouseout", function() {
     $(this).destroy();
      $(this).unbind();
});`

我一直在使用它,而destroy方法会停止动画。