标签:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>suface js判断css动画是否结束</title>
</head>
<body>
<p>一旦动画或变换结束,回调函数就会触发。不再需要大型类库支持。<br>
http://www.webhek.com/css-animation-callback/ 来源于web骇客</p>
<style type="text/css">
.sample {
width: 200px;
height: 200px;
border: 1px solid green;
background: lightgreen;
opacity: 1;
margin-bottom: 20px;
transition-property: opacity;
/*transition-duration: .5s;*/
transition-duration:3s;
}
.sample.hide {
opacity: 0;
}
</style>
<div class="sample">css3动画过度慢慢隐藏(transition-duration:3s;)</div>
<p><button onclick="this.style.display=‘none‘;startFade();">慢慢消退,检测结束事件</button></p>
<script type="text/javascript">
(function() {
var e = document.getElementsByClassName(‘sample‘)[0];
function whichTransitionEvent(){
var t;
var el = document.createElement(‘fakeelement‘);
var transitions = {
‘transition‘:‘transitionend‘,
‘OTransition‘:‘oTransitionEnd‘,
‘MozTransition‘:‘transitionend‘,
‘WebkitTransition‘:‘webkitTransitionEnd‘
};
for(t in transitions){
if( el.style[t] !== undefined ){
return transitions[t];
}
}
}
var transitionEvent = whichTransitionEvent();
transitionEvent && e.addEventListener(transitionEvent, function() {
alert(‘css3运动结束!我是回调函数,没有使用第三方类库!‘);
});
startFade = function() {
e.className+= ‘ hide‘;
}
})();</script>
<br>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/Silababy/p/4354440.html