简体   繁体   English

如果鼠标悬停在按钮上但移动,动画将重置

[英]Animation resets if mouse is hovering over the button but moves

I'm new to web developing and haven't found a solution for this. 我是Web开发的新手,还没有找到解决方案。 I have made a small website with a word that when the mouse hovers over it, a picture slides down while fading in, and when you move off the word, it slides back up and disappears. 我创建了一个小型网站,上面有一个单词,当鼠标悬停在它上面时,图片会在淡入时向下滑动,而当您移开该单词时,它会向上滑动并消失。

The problem is that if I hover over the word and the animation runs, if I move the mouse slightly while still hovering over the word, the animation reverses. 问题是,如果将鼠标悬停在单词上,动画就会运行,如果在将鼠标悬停在单词上时稍微移动鼠标,动画会倒转。 So basically, I'm on the word, the picture slides down, I move slightly (but still on it), the picture goes back up. 所以基本上,我的意思是,图片向下滑动,我稍微移动(但仍在上面),图片又向上移动。 That means that moving the mouse over a word makes this weird jerk motion with the picture, where it goes up and down a few times until you're off the word. 这意味着将鼠标移到一个单词上会使图片产生这种怪异的混蛋动作,该动作会上下移动几次,直到您离开单词为止。

I would love a simple example of something similar, where moving the mouse on the word while already being on it, not affect the animation, and have it reverse ONLY when the mouse is completely off of it. 我喜欢一个类似的简单示例,其中在已经在单词上移动鼠标时,不影响动画,只有在鼠标完全离开时才使动画反向。

Thank you so much, if you have any questions, ask away! 非常感谢,如果您有任何疑问,请走开!

You could do this: 您可以这样做:

$( "#element" ).mouseover(function() {
      //Animate in
    });
    $( "#element" ).mouseleave(function() {
       //Animate out
      });

Css(not too steady in css, but I think you can do something like this): CSS(在CSS中不太稳定,但是我认为您可以执行以下操作):

.object{
 top:0;
 animation-duration: 4s;
}
  .element:hover ~ .object{
  top:50px;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM