Find out if any transition is in progress

流过昼夜 提交于 2020-01-03 20:01:03

问题


Is there anyway to find out if there currently is a transition running on my page? Not on a specific element but globally for the whole page?

Thanks


回答1:


To see when a css transition has ended you can use transitionend.

The transitionend event is fired when a CSS transition has completed.

source: https://developer.mozilla.org/en-US/docs/Web/Reference/Events/transitionend

Where you can just use 'flags' to see when the animation has completed and when not. Here an example:

var AnimationComplete;

$('div').click(function() {
    $(this).addClass('green');
    AnimationComplete= false;
    console.log(AnimationComplete);
});

$("*").bind("transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd", function() {
    AnimationComplete= true;
    alert('animate ended');
    console.log(AnimationComplete);    
    return false; /*Cancel any bubbling*/
});

I have to say it is a BAD practice to use the * selector, as it will bind these event[s] to all the element. It is better to write your specific elements in there.

jsFiddle

Update

So basically how you determ that a transition is in progress is when my 'flag' AnimionComplete is false.

jsFiddle

Here can you see 3 different states: start, in progress and end.



来源:https://stackoverflow.com/questions/20949473/find-out-if-any-transition-is-in-progress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!