$(elem).css('backgroundPositionY')
does it on chrome, ie, and safari, but not Firefox (nor Opera I believe). You'd think jQuery would have a polyfill but it doesn't, as of 1.5. How can I easily get the background Y position for e.g. background animations (for e.g. parallax)?
EDIT: Tell Mozilla you want background-position-[x,y]
support. (use the "vote" feature, not comment, unless you have something prescient to add). Bug has been open since 2010 tho (3 years now) so don't hold your breath for a fix. :)
click(function() { var color = $( this ). css( "background-color" ); $( "p" ). html( "That div is " + color + "." ); });
The background-position-y CSS property sets the initial vertical position for each background image. The position is relative to the position layer set by background-origin .
The background-position property sets the starting position of a background image. Tip: By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.
The background-attachment property specifies whether a background image is fixed with regard to the viewport or scrolls along with the containing block.
var backgroundPos = $(elem).css('backgroundPosition').split(" ");
//now contains an array like ["0%", "50px"]
var xPos = backgroundPos[0],
yPos = backgroundPos[1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With