animate.css:悬停脚本动画



我试图使用JS完成悬停动画,但我使用上述语言的技能非常有限。我在script.js文件中有这个脚本,因为它是我使用的唯一脚本:

$(document).ready(function() {
    animationHover('#intro-logo' 'tada')
function animationHover(element, animation){
    element = $(element);
    element.hover(
        function() {
            element.addClass('animated ' + animation);          
        },
        function(){
            //wait for animation to finish before removing classes
            window.setTimeout( function(){
                element.removeClass('animated ' + animation);
            }, 2000);           
        });
}
}
})();

目标是,当我将鼠标悬停在#intro徽标上时,脚本将添加类.animated和.tada,这将使该死的东西动画化!然而,我得到了Uncaught SyntaxError:意外的字符串,它将我带到

animationHover('#intro-logo' 'tada')

我不知道我做错了什么,我在这里用了一个教程,它对那个人有效,但我没有这样的运气。我真诚地感谢任何人的帮助。

提前谢谢你,这个社区太棒了。这是我的第一个问题,但在我艰难的网络开发之路中,你们所有人都帮助我解决了数百个问题(其中大部分显然仍在前方)。

编辑:我添加了缺失的逗号,现在看来我结束文档的方式有问题。发布的是我的整个JS文件,如何正确关闭所有内容?})();似乎不起作用。

工作示例:

$(document).ready(function () {
    animationHover('#intro-logo', 'tada')
    function animationHover(element, animation) {
        element = $(element);
        element.hover(
        function () {
            element.addClass('animated ' + animation);
        },
        function () {
            //wait for animation to finish before removing classes
            window.setTimeout(function () {
                element.removeClass('animated ' + animation);
            }, 2000);
        });
    }
});

删除了末尾不必要的}(),并添加了逗号。

如果您不一定需要JS,可以使用jQuery:

$(document).ready(function() {
        $("#intro-logo").hover(function () {
             $(this).toggleClass('animated tada');
     });
   });

工作jsfiddle

或者,您也可以在纯CSS中使用:hover伪类

最新更新