-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.aniclip.js
62 lines (48 loc) · 1.78 KB
/
jquery.aniclip.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
(function ($, undefined) {
var autoString = 'auto';
function parseClipString(clipString) {
return clipString.match(/(\d+\w+|auto)/g);
}
function sanitizeClipParts(clipParts) {
for (var i = 0; i < 4; i++) {
var partNumber = parseInt(clipParts[i]);
clipParts[i] = isNaN(partNumber) ? clipParts[i] : partNumber;
}
return clipParts;
}
function styleToParts(element) {
var clipString = $.css(element, 'clip');
var clipParts;
if (!clipString) {
clipParts = [$.css(element, 'clipTop'), $.css(element, 'clipRight'), $.css(element, 'clipBottom'), $.css(element, 'clipLeft')];
}
else if (clipString === autoString) {
clipParts = [autoString, autoString, autoString, autoString];
}
else {
clipParts = parseClipString(clipString);
}
return sanitizeClipParts(clipParts);
}
function stringToParts(clipString) {
var clipParts = parseClipString(clipString);
return sanitizeClipParts(clipParts);
}
$.fx.step['clip'] = function (fx) {
if (fx.pos === 0 && typeof fx.start !== 'object' && typeof fx.end !== 'object') {
fx.start = styleToParts(fx.elem);
fx.end = stringToParts(fx.end);
}
var clipParts = [];
for (var i = 0; i < 4; i++) {
var startValue = fx.start[i];
var endValue = fx.end[i];
if (startValue === autoString || endValue === autoString) {
clipParts.push(autoString);
continue;
}
clipParts.push(startValue + (endValue - startValue) * fx.pos + 'px');
}
fx.elem.style.clip = 'rect(' + clipParts.join(' ') + ')';
};
})(jQuery);