-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtansform结束.html
57 lines (49 loc) · 1.78 KB
/
tansform结束.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>suface js判断css动画bai是否结du束</title>
</head>
<body>
<p>一旦动画或变换结束,回zhi调函数就会触发。dao不再需要大型类库支持。 </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>
;
(function () {
var e = document.getElementsByClassName('sample')[0];
function whichTransitionEvent() {
var t,
el = document.createElement('surface'),
transitions = {
'transition': 'transitionend',
'OTransition': 'oTransitionEnd',
'MozTransition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd'
}
for (t in transitions) {
if (el.style[t] !== undefined) {
return transitions[t];
}
}
}
var transitionEvent = whichTransitionEvent();
console.log(transitionEvent)
// transitionEvent && e.addEventListener(transitionEvent, function () {
// alert('css3运动结束!我是回调函数,没有使用第三方类库!');
// e.removeEventListener(transitionEvent, arguments.callee, false); //销毁事件
// });
startFade = function () {
e.className += ' hide';
}
})();
</script>
</body>
</html>//兼容性 详情