我做了一个fiddle ,想法是:
该函数接受一个元素 (el),如果“el”在 fadeIn 或 fadeOut 中,则返回 true,否则返回 false。可能吗?
function fadeIsRunning( el ){
/* How to achieve this ? */
return false || true;
}
提前致谢!
var obj = $("div");
$("#fade").on("click", function(){
obj.fadeToggle(3000);
});
$("#decision").on("click", function(){
if (fadeIsRunning(obj)) {
console.log( "Fade is running" );
}
else {
console.log( "Fade isn't running" );
}
});
function fadeIsRunning( el ){
/* How to achieve this ? */
return false || true;
}
div {
position: absolute;
margin: 20px;
padding: 35px;
background-color: #99f;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="button" value="fade" id="fade" />
<input type="button" value="decision" id="decision" />
<div>X</div>
最佳答案
您可以组合 .is()
method和 :animated
selector , .is(':animated')
,以确定元素是否正在主动淡入淡出。
function fadeIsRunning( el ){
return $(el).is(':animated');
}
引用文献:
关于jquery - 我如何知道是否正在发生淡入淡出效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28968199/