我怎么知道是否发生了淡入淡出效果?

How do I know if a fade effect is occurring?

我做了一个fiddle,思路是:

该函数接受一个元素 (el),如果 "el" 在 fadeIn 或 fadeOut 中,则返回 true,否则 return 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 and the :animated selector.is(':animated') 来确定元素是否正在主动淡化。

Updated Example

function fadeIsRunning( el ){
    return $(el).is(':animated');
}

参考文献:

jsFiddle Demo

检查 jquery 中的 fx queue jQuery 以查看元素的进度。如果它在 fx 队列中并且正在衰落,则其状态将为 "inprogress"

function fadeIsRunning( el ){
 return $.queue(el[0]) == "inprogress";
}