forked from brandonaaron/jquery-cssHooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scale.js
100 lines (88 loc) · 2.83 KB
/
scale.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* scale: A jQuery cssHooks adding a cross browser 'scale' property to $.fn.css() and $.fn.animate()
*
* limitations:
* - requires jQuery 1.4.3+
* - using composit values (e.g. 1.7,0.6) requires jQuery trunk
* - cannot be used together with jquery.rotate.js
*
* Copyright (c) 2010 Louis-Rémi Babé twitter.com/louis_remi
* Licensed under the MIT license.
*
* This saved you an hour of work?
* Send me music http://www.amazon.fr/wishlist/HNTU0468LQON
*
*/
(function($) {
var div = document.createElement('div'),
divStyle = div.style,
support = $.support;
support.transform =
divStyle.MozTransform === ''? 'MozTransform' :
(divStyle.MsTransform === ''? 'MsTransform' :
(divStyle.WebkitTransform === ''? 'WebkitTransform' :
(divStyle.OTransform === ''? 'OTransform' :
(divStyle.transform === ''? 'transform' :
false))));
support.matrixFilter = !support.transform && divStyle.filter === '';
div = null;
$.cssNumber.scale = true;
$.cssHooks.scale = {
set: function( elem, value ) {
var _support = support,
supportTransform = _support.transform,
scales,
centerOrigin;
$.data( elem, 'transform', {
// convert value to an array
scale: scales = value.toString().split(',')
});
if (supportTransform) {
elem.style[supportTransform] = 'scale('+ value +')';
} else if (_support.matrixFilter) {
elem.style.filter = [
"progid:DXImageTransform.Microsoft.Matrix(",
"M11="+scales[0]+",",
"M12=0,",
"M21=0,",
"M22="+scales [1]+",",
"SizingMethod='auto expand'",
")"
].join('');
// From pbakaus's Transformie http://github.com/pbakaus/transformie
if(centerOrigin = $.scale.centerOrigin) {
elem.style[centerOrigin == 'margin' ? 'marginLeft' : 'left'] = -(elem.offsetWidth/2) + (elem.clientWidth/2) + "px";
elem.style[centerOrigin == 'margin' ? 'marginTop' : 'top'] = -(elem.offsetHeight/2) + (elem.clientHeight/2) + "px";
}
}
},
get: function( elem ) {
var transform = $.data( elem, 'transform' );
return transform && transform.scale? transform.scale : 0;
}
};
$.fx.step.scale = function( fx ) {
// fx.start is not correctly initialised by jQuery, fix it once for all
if ( !$.isArray(fx.start) ) {
fx.start = $.data( fx.elem, 'transform').scale;
}
var start = fx.start,
end = fx.end.toString().split(',');
// In case of composit value, we need to recalculate fx.now
if (start.length == 2 || end.length == 2) {
if (!start[1]) {
start[1] = start[0];
}
if (!end[1]) {
end[1] = end[0];
}
fx.now =
+(+start[0] + fx.pos * (+end[0] - start[0])) + ','+
+(+start[1] + fx.pos * (+end[1] - start[1]));
}
$.cssHooks.scale.set( fx.elem, fx.now );
};
$.scale = {
centerOrigin: 'margin'
};
})(jQuery);