首页 > 解决方案 > 我的 jQuery animate() 运行了 2 次,如何解决这个问题?

问题描述

我用animatejQuery的功能做了一些动画。当函数启动时,它运行 2 次;div 下降,上升,最后下降。

我不知道如何解决这个问题。

$("#p1 br").css("display","none");
$("#p12 br").css("display","none");
$("#p13 br").css("display","none");

$("#cryptosmart").mouseover(function() {
  $("#cryptobox").animate({top: "1403.5px"});
  $("#cryptopass").css("top","1591.5px");
});
$("#cryptosmart").mouseout(function() {
  $("#cryptobox").animate({top: "1201px"});
  $("#cryptopass").css("top","1389px");
});
$("#cryptobox").mouseover(function() {
  $("#cryptopass").css("top","1591.5px");
});
$("#cryptobox").mouseout(function() {
  $("#cryptopass").css("top","1389px");
});

标签: jquerycss

解决方案


我不知道你的问题,因为我没有看到。你可以分享 jsfiddle/codepen 或堆栈片段吗?

但是你应该用 jQueryhover函数试试这个。该函数可以使用两个参数。像这样;

$("#cryptosmart").hover(
    function(){ //mouseenter
        $("#cryptobox").animate({top: "1403.5px"});
        $("#cryptopass").css("top","1591.5px");
    },
    function(){ //mouseleave
        $("#cryptobox").animate({top: "1201px"});
        $("#cryptopass").css("top","1389px");
    }
);

推荐阅读