简体   繁体   English

如何覆盖CSS动画

[英]How to overwrite css animation

I've an alert div, once it pops up I've to wait till it disappear completely before the next animation can occur. 我有一个警报div,一旦它弹出,我就必须等到它完全消失后才能播放下一个动画。 Is there any way to ignore/cancel the animation and let it be overwritten with new one? 是否有任何方法可以忽略/取消动画并让其被新动画覆盖? So it re-alert very time I hover the button. 因此,当我将按钮悬停时,它会重新发出警报。

$('.button').hover(function () {
  $('#alert-me').show();
  $("#alert-me").fadeOut(6000);
});


<div class="hidden-div" id="alert-me">
     <b> hello! </b>
</div>    

inside the callback of show() method you can hide it. show()方法的回调中,您可以将其隐藏。

$('.button').hover(function () {
  $('#alert-me').show(function(){
    $("#alert-me").fadeOut(6000);
  });

});

A simple option would be to .finish() the animation before you .show() it. 一个简单的选择是在.finish()动画之前.show()动画。

Working Example: 工作示例:

 $('.button').hover(function () { $('#alert-me').finish().show(); $("#alert-me").fadeOut(6000); }); 
 .hidden-div { display: none; } .button { border: 1px solid grey; padding: 0.5em; margin: 0.5em; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="button">button</div> <div class="hidden-div" id="alert-me"> <b> hello! </b> </div> 

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

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