2013-05-31 74 views
5

有没有办法在我的JavaScript来检测,如果一个元素,目前正在与CSS3过渡动画?检查CSS3过渡运行

的“transitionstart” -event(相当于“transistionend”事件)也将工作,但我无法找到规范的任何提及。

+1

http://stackoverflow.com/questions/2794148/css3-transition-events,http://stackoverflow.com/questions/ 7264899/detect-css-transitions-using-javascript-and-without-modernizr? – coma

+1

这很不幸,因为第一个链接中的答案关注“transistionend”,而第二个链接仅讨论css3过渡的特征检测。 :/ – johnny

+0

你发现我的答案有用吗? – coma

回答

2

好,因为只有一个transitionend事件(http://www.w3.org/TR/css3-transitions/#transition-events)一些丑陋在我脑海中:

http://jsfiddle.net/coma/psbBg/6/

JS

$(function() { 

    var div = $('div'); 
    var property = div.css('transition-property'); 
    var lastValue = div.css(property); 

    setInterval(function() { 

     if(lastValue !== div.css(property)) { 

      console.log('changed!'); 

     } 

     lastValue = div.css(property); 

    }, 10); 

}); 

它可以实现自定义的事件加以改进,照顾获得正确的过渡财产(或属性),和更多的想法,但你得到的照片是正确的?

也许你需要解决您的原始问题的另一个路径...

+2

我认为你的意思是检查'变形'属性而不是'过渡',对吧?但我明白了。这似乎有点暴躁,但它可能是唯一的出路。谢谢! – johnny

+0

哦,谢谢你指出,现在我正在使用transition-property:http://jsfiddle.net/coma/psbBg/6/ – coma