Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the background-position-y in firefox using jQuery?

$(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. :)

like image 615
Stop Slandering Monica Cellio Avatar asked Jul 25 '11 20:07

Stop Slandering Monica Cellio


People also ask

How can check background color in jquery?

click(function() { var color = $( this ). css( "background-color" ); $( "p" ). html( "That div is " + color + "." ); });

What is background position y in CSS?

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 .

What is the default position of a background image in a Web page?

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.

Which property specifies whether the background image is positioned?

The background-attachment property specifies whether a background image is fixed with regard to the viewport or scrolls along with the containing block.


1 Answers

var backgroundPos = $(elem).css('backgroundPosition').split(" ");
//now contains an array like ["0%", "50px"]

var xPos = backgroundPos[0],
    yPos = backgroundPos[1];
like image 71
Stop Slandering Monica Cellio Avatar answered Sep 29 '22 00:09

Stop Slandering Monica Cellio