我得到了一个下拉切换(id="actions")与html中的图像(id=imgAction)。我在javascript中添加了脚本
$(document).ready(function() {
    var el = document.getElementById("actions");
    if (el.addEventListener)
        el.onmouseover = tadaAnimation;
    function tadaAnimation() {
        $(imgAction).toggleClass('animated tada');
    }
 });而且它每隔一秒就能工作一次。为什么每次我悬停下拉切换时它都不起作用。
发布于 2017-08-01 20:52:41
主要问题是您只绑定了mouseover事件处理程序。您还需要附加mouseout事件处理程序
每次鼠标进入或离开某个子元素时,都会触发mouseover,但不会触发mouseenter。因此,我建议您使用mouseenter而不是mouseover
因为您正在使用使用它的jQuery绑定事件。我建议您使用.hover()
$(document).ready(function () {
    function tadaAnimation() {
        $("#imgAction").toggleClass('animated tada');
    }
    $("#actions").hover(tadaAnimation, tadaAnimation)
});https://stackoverflow.com/questions/45438255
复制相似问题