码迷,mamicode.com
首页 > Web开发 > 详细

网页动画结束判断事件

时间:2015-03-20 20:23:04      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:

<!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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!