我使用jQuery鼠标输入/鼠标离开来执行带有我的徽标的功能。我也使用Animate.css。
$(".logo-1").mouseenter(function() {
$(this).css("display", "none");
$(".logo-2").css("display", "inline-block");
$("#facebook").css("visibility", "visible").css("-webkit-animation-duration", "0.1s").addClass("animated fadeInDown").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#linked").css("visibility", "visible").css("-webkit-animation-duration", "0.1s").addClass("animated fadeInDown").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#instagram").css("visibility", "visible").css("-webkit-animation-duration", "0.1s").addClass("animated fadeInDown").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#github").css("visibility", "visible").css("-webkit-animation-duration", "0.1s").addClass("animated fadeInDown").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#facebook, #linked, #instagram, #github").removeClass("animated fadeInDown")
});
});
});
});
});
$(".logo-social").mouseleave(function() {
$("#github").addClass("animated fadeOutUp").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#instagram").addClass("animated fadeOutUp").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#linked").addClass("animated fadeOutUp").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#facebook").addClass("animated fadeOutUp").one("animationend oAnimationEnd mozAnimationEnd webkitAnimationEnd",
function() {
$("#facebook, #linked, #instagram, #github").removeClass("animated fadeOutUp").css("visibility", "hidden");
$(".logo-2").css("display", "none");
$(".logo-1").css("display", "inline-block");
});
});
});
});
});HTML:
<div class="logo-social">
<div class="dg">
<img src="img/logo-1.png" class="logo-1" alt="logo">
<img src="img/logo-2.png" class="logo-2" alt="logo">
</div>
<div class="wrapper">
<div class="media-links-1">
<a href="https://www.facebook.com/gorniczy" target="_blank"><img src="img/facebook-logo-dark.png" id="facebook" alt="Facebook logo"></a>
<a href="https://www.linkedin.com/in/denis-gornichar-56b3b564/" target="_blank"><img src="img/linkedin-sign-dark.png" id="linked" alt="LinkedIn logo"></a>
<a href="https://www.instagram.com/gorniczy/" target="_blank"><img src="img/instagram-symbol-dark.png" id="instagram" alt="Instagram logo"></a>
<a href="https://github.com/gorniczy" target="_blank"><img src="img/github-sign-dark.png" id="github" alt="Github logo"></a>
</div>
</div>
</div>当我等待鼠标输入函数完成后再将光标移动到其他地方时,一切都很正常。但是如果我在第一个函数完成之前移动光标,它就会被第二个函数中断,这会导致错误。
我希望我的mouseleave函数只在mousenter函数完成后才开始执行,无论我何时将光标移动到其他地方。
发布于 2018-10-14 07:28:57
你的动画有4~5个回调堆栈。
所以我理解你为什么想要研究“触发预防”。
这是一种使用“标志”的方法。每个"disabled“状态对应一个...如果鼠标在徽标内或外,则为always now。
然后,使用超时和这些标志,您可以阻止动画执行...同时确保在"in“结束后鼠标不在的情况下执行" out”动画。
var disableIn = false,
disableOut = false,
animationDelayIn = 600, // Set those two delays based on your animation times
animationDelayOutIn = 600,
currentlyIn = false;
$(".logo").mouseenter(function(){
currentlyIn = true;
if(!disableIn){
//otherAnimation
}
// Toggle the flag during the animation
disableIn = true;
setTimeout(function(){
disableIn = false;
},animationDelayIn);
});
$(".logo").mouseleave(function(){
currentlyIn = false;
if(!disableOut){
//otherAnimation
}
// Toggle the flag during the animation
disableOut = true;
setTimeout(function(){
disableOut = false;
if(!currentlyIn){
$(".logo").trigger("mouseleave"); // If the mouse is out, yeah, do the out animation now.
}
},animationDelayOut);
});免责声明:这是一个很好的开端...它需要用你的动画进行测试。;)
https://stackoverflow.com/questions/52798065
复制相似问题