PageSourceSearch

https://csemo.hu/include/jquery.backgroundpos.js

js csemo.hu collected 2026-10-07 20:36:08 UTC 3,170 bytes, 87 lines download raw bytes

1/* http://keith-wood.name/backgroundPos.html
2   Background position animation for jQuery v1.1.0.
3   Written by Keith Wood (kbwood{at}iinet.com.au) November 2010.
4   Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and 
5   MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 
6   Please attribute the author if you use it. */
7
8(function($) { // Hide scope, no $ conflict
9
10var BG_POS = 'bgPos';
11
12var usesTween = !!$.Tween;
13
14if (usesTween) { // jQuery 1.8+
15	$.Tween.propHooks['backgroundPosition'] = {
16		get: function(tween) {
17			return parseBackgroundPosition($(tween.elem).css(tween.prop));
18		},
19		set: function(tween) {
20			setBackgroundPosition(tween);
21		}
22	};
23}
24else { // jQuery 1.7-
25	// Enable animation for the background-position attribute
26	$.fx.step['backgroundPosition'] = setBackgroundPosition;
27};
28
29/* Parse a background-position definition: horizontal [vertical]
30   @param  value  (string) the definition
31   @return  ([2][string, number, string]) the extracted values - relative marker, amount, units */
32function parseBackgroundPosition(value) {
33	var bgPos = (value || '').split(/ /);
34	var presets = {center: '50%', left: '0%', right: '100%', top: '0%', bottom: '100%'};
35	var decodePos = function(index) {
36		var pos = (presets[bgPos[index]] || bgPos[index] || '50%').
37			match(/^([+-]=)?([+-]?\d+(\.\d*)?)(.*)$/);
38		bgPos[index] = [pos[1], parseFloat(pos[2]), pos[4] || 'px'];
39	};
40	if (bgPos.length == 1 && $.inArray(bgPos[0], ['top', 'bottom']) > -1) {
41		bgPos[1] = bgPos[0];
42		bgPos[0] = '50%';
43	}
44	decodePos(0);
45	decodePos(1);
46	return bgPos;
47}
48
49/* Set the value for a step in the animation.
50   @param  fx  (object) the animation properties */
51function setBackgroundPosition(fx) {
52	if (!fx.set) {
53		initBackgroundPosition(fx);
54	}
55	$(fx.elem).css('background-position',
56		((fx.pos * (fx.end[0][1] - fx.start[0][1]) + fx.start[0][1]) + fx.end[0][2]) + ' ' +
57		((fx.pos * (fx.end[1][1] - fx.start[1][1]) + fx.start[1][1]) + fx.end[1][2]));
58}
59
60/* Initialise the animation.
61   @param  fx  (object) the animation properties */
62function initBackgroundPosition(fx) {
63	var elem = $(fx.elem);
64	var bgPos = elem.data(BG_POS); // Original background position
65	elem.css('backgroundPosition', bgPos); // Restore original position
66	fx.start = parseBackgroundPosition(bgPos);
67	fx.end = parseBackgroundPosition($.fn.jquery >= '1.6' ? fx.end :
68		fx.options.curAnim['backgroundPosition'] || fx.options.curAnim['background-position']);
69	for (var i = 0; i < fx.end.length; i++) {
70		if (fx.end[i][0]) { // Relative position
71			fx.end[i][1] = fx.start[i][1] + (fx.end[i][0] == '-=' ? -1 : +1) * fx.end[i][1];
72		}
73	}
74	fx.set = true;
75}
76
77/* Wrap jQuery animate to preserve original backgroundPosition. */
78$.fn.animate = function(origAnimate) {
79	return function(prop, speed, easing, callback) {
80		if (prop['backgroundPosition'] || prop['background-position']) {
81			this.data(BG_POS, this.css('backgroundPosition') || 'left top');
82		}
83		return origAnimate.apply(this, [prop, speed, easing, callback]);
84	};
85}($.fn.animate);
86
87})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.