Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery backgroundPosition Animation Question

I am using Jquery to animate an object while the user presses a key.

Upon Keyup the object stops moving, but I need to know what the background position of the object is when it stops. Using .stop(true);

Without getting to much into it, I need to be able to get the position of the background. Is there anyway with Javascript or jquery to obtain those numbers?

like image 318
Case Avatar asked Mar 20 '26 17:03

Case


2 Answers

If you are changing the background position coordinates, you will be able to get the computed style of the element, at the moment you stop the animation simply by using the css method.

It will return you a pair of pixel values separated by a space, something like "Xpx Ypx", you can split that values and use them separately:

var position = $(selector).css('backgroundPosition').split(' '),// ["0px", "0px"]
x = position[0], y = position[1];
like image 149
Christian C. Salvadó Avatar answered Mar 22 '26 08:03

Christian C. Salvadó


You should be able to identify the specific element that has the background image. Then you can use .offset - http://docs.jquery.com/CSS/offset - to get the left/top absolute position of the element with respect to the page.

like image 32
Chad Avatar answered Mar 22 '26 08:03

Chad