【问题标题】:How do I know if a fade effect is occurring?我如何知道是否正在发生淡入淡出效果?
【发布时间】:2015-03-10 15:51:22
【问题描述】:

我做了一个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>

【问题讨论】:

    标签: jquery fade


    【解决方案1】:

    您可以将.is() method:animated selector.is(':animated') 组合起来,以确定元素是否正在被淡化。

    Updated Example

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

    参考资料:

    【讨论】:

      【解决方案2】:

      jsFiddle Demo

      检查 jquery 中的 fx queue jQuery 以查看元素的进度。如果它在 fx 队列中并且正在淡出,它的状态将是“进行中”

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

      【讨论】:

      • 哇.. 你也明白了!你们真是不可思议!
      猜你喜欢
      • 1970-01-01
      • 2011-03-05
      • 2011-10-16
      • 1970-01-01
      • 2011-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多