-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathjquery.backgroundPosition.js
executable file
·41 lines (40 loc) · 1.35 KB
/
jquery.backgroundPosition.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
/*! Copyright (c) 2011 Peter (Poetro) Galiba (http://poetro.hu/) MIT Licensed */
/**
* @fileoverview CSS get/set and animate background position values independently.
* @author Peter (Poetro) Galiba poetro@poetro.hu
* @example
* // Get the CSS background positions's X component
* $(elem).css('background-position-x');
* // Set the CSS background positions's Y component
* $(elem).css('background-position-y', 0);
* // Animate the background positions X and Y component
* $(elem).animate({
* backgroundPositionY: '100%',
* backgroundPositionX: '100%'
* }, 1000);
* @requires jQuery 1.4.3+
*/
(function ($) {
var bgpos = 'background-position', cc = $.camelCase;
function normalize(value) {
var h = '100%', z = '0px', options = {top : z, bottom: h, left: z, right: h};
return options[value] || value;
}
$.each(['x', 'y'], function (i, v) {
var camelCase = cc(bgpos + '-' + v);
$.cssHooks[camelCase] = {
get: function (elem) {
var pos = $.css(elem, bgpos).split(/\s+/, 2);
return normalize(pos[i]);
},
set: function (elem, value) {
var pos = $.css(elem, bgpos).split(/\s+/, 2);
pos[i] = normalize(value);
$.style(elem, bgpos, pos.join(' '));
}
};
$.fx.step[camelCase] = function (fx) {
$.style(fx.elem, fx.prop, fx.now);
};
});
}(jQuery));