-
Notifications
You must be signed in to change notification settings - Fork 4
/
jquery.betterToggle.js
50 lines (44 loc) · 1.63 KB
/
jquery.betterToggle.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
(function($) {
$.fn.betterToggle = function(options) {
var elem = this;
var vendorprefix = getVendorPrefix(),
transform = "-" + vendorprefix + "-transform",
obj = {},
hidden = elem.is(":visible"),
number;
hidden ? number = 1 : number = 0;
var handle = setInterval(
function() {
hidden ? number -= 0.1 : number += 0.1;
if (!hidden) {
elem.show();
}
obj[transform] = "scale(" + number + ")";
elem.css(obj);
if (number <= 0) {
obj[transform] = "scale(0)";
elem.css(obj);
elem.hide();
clearInterval(handle)
} else if (number >= 1) {
obj[transform] = "scale(1)";
elem.css(obj);
clearInterval(handle)
};
}, 30);
function getVendorPrefix() {
if ('result' in arguments.callee) return arguments.callee.result;
var regex = /^(Moz|Webkit|Khtml|O|ms|Icab)(?=[A-Z])/;
var someScript = document.getElementsByTagName('script')[0];
for (var prop in someScript.style) {
if (regex.test(prop)) {
return arguments.callee.result = prop.match(regex)[0];
}
}
if ('WebkitOpacity' in someScript.style) return arguments.callee.result = 'Webkit';
if ('KhtmlOpacity' in someScript.style) return arguments.callee.result = 'Khtml';
return arguments.callee.result = '';
}
return elem;
};
})(jQuery);