Return to Snippet

Revision: 43168
at March 18, 2011 04:39 by FlashJunior


Updated Code
<script type="text/javascript">
//<![CDATA[

function getBackgroundPos(obj) {
	var pos = obj.css("background-position");
	if (pos == 'undefined' || pos == null) {
		pos = [obj.css("background-position-x"),obj.css("background-position-y")];//i hate IE!!
	} else {
		pos = pos.split(" ");
	}
	return {
		x: parseFloat(pos[0]),
		xUnit: pos[0].replace(/[0-9-.]/g, ""),
		y: parseFloat(pos[1]),
		yUnit: pos[1].replace(/[0-9-.]/g, "")
	};
}

$(document).ready(function() {		
	// Test:
	// getBackgroundPos($("body")).x
	// getBackgroundPos($("body")).xUnit
	// getBackgroundPos($("body")).y
	// getBackgroundPos($("body")).yUnit
	//
});

//]]>
</script>

Revision: 43167
at March 18, 2011 04:36 by FlashJunior


Updated Code
function getBackgroundPos(obj) {
	var pos = obj.css("background-position");
	if (pos == 'undefined' || pos == null) {
		pos = [obj.css("background-position-x"),obj.css("background-position-y")];
	} else {
		pos = pos.split(" ");
	}
	return {
		x: parseFloat(pos[0]),
		xUnit: pos[0].replace(/[0-9-.]/g, ""),
		y: parseFloat(pos[1]),
		yUnit: pos[1].replace(/[0-9-.]/g, "")
	};
}
			
// Test:
// getBackgroundPos($("body")).x
// getBackgroundPos($("body")).xUnit
// getBackgroundPos($("body")).y
// getBackgroundPos($("body")).yUnit
//

Revision: 43166
at March 18, 2011 04:34 by FlashJunior


Initial Code
function getBackgroundPos(obj) {
				var pos = obj.css("background-position");
				if (pos == 'undefined' || pos == null) {
					pos = [obj.css("background-position-x"),obj.css("background-position-y")];
				} else {
					pos = pos.split(" ");
				}
				return {
					x: parseFloat(pos[0]),
					xUnit: pos[0].replace(/[0-9-.]/g, ""),
					y: parseFloat(pos[1]),
					yUnit: pos[1].replace(/[0-9-.]/g, "")
				};
			}
			
			// Test:
			// getBackgroundPos($("body")).x
			// getBackgroundPos($("body")).xUnit
			// getBackgroundPos($("body")).y
			// getBackgroundPos($("body")).yUnit
			//

Initial URL

                                

Initial Description

                                

Initial Title
get background-image position (x y and unit)

Initial Tags
image, jquery, background

Initial Language
jQuery