JQuery backgroundPosition animation question

I use jQuery to animate an object while the user presses a key.

After 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 going into it, I need to be able to get the background position. Is there anyway javascript or jquery to get these numbers?

+3
source share
4 answers

If you change the coordinates of the background position, you can get the calculated style of the element, at the moment you stop the animation just using css.

, , - "Xpx Ypx", :

var position = $(selector).css('backgroundPosition').split(' '),// ["0px", "0px"]
x = position[0], y = position[1];
+2
+1

Have you tried this?

$('#yourOject').css('backgroundPosition')

It should return something like "nnpx yypx".

0
source
var position = $(selector).css('backgroundPosition').split(' '),// ["0px", "0px"]
x = position[0], y = position[1];

It was almost perfect, the only thing I changed was split ('px') so you could have a raw number when you use it for other calculations.

-1
source

Source: https://habr.com/ru/post/1729171/


All Articles