forked from yanlele/node-index
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtransition.js
65 lines (54 loc) · 1.63 KB
/
transition.js
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
58
59
60
61
62
63
64
65
/**
* Transition.js
* Copyright (c) 2016 xyzhanjiang & contributors
*
* Licensed under the MIT License.
*
* @author xyzhanjiang <[email protected]>
*/
+(function(root, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = factory(require('jquery'));
} else {
root.transition = factory(root.jQuery || root.Zepto);
}
}(this, function($) {
var transitionEndEventName = 'customTransitionEnd';
function transitionEnd() {
var el = document.createElement('div');
var transEndEventNames = {
transition : 'transitionend',
WebkitTransition : 'webkitTransitionEnd',
MozTransition : 'transitionend',
OTransition : 'oTransitionEnd otransitionend'
};
for (var name in transEndEventNames) {
if (el.style[name] !== undefined) {
return { end: transEndEventNames[name] };
}
}
return false; // explicit for ie8
}
// {end: 'transitionend'}
var transition = $.support.transition = transitionEnd();
// http://blog.alexmaccaw.com/css-transitions
// 模拟事件,防止事件意外不触发
$.fn.emulateTransitionEnd = function(duration) {
var called = false;
var $el = this;
$(this).one(transitionEndEventName, function() { called = true; });
var callback = function() { if (!called) $($el).trigger(transition.end); };
setTimeout(callback, duration);
return this;
};
if (transition) {
$.event.special[transitionEndEventName] = {
bindType: transition.end,
delegateType: transition.end,
handle: function(e) {
if ($(e.target).is(this)) return e.handleObj.handler.apply(this, arguments);
}
};
}
return transition;
}));