开发者

Jquery backgroundPosition Animation Question

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

Upon Keyup the object stops mo开发者_如何学Goving, 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?


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];


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.


Have you tried this?

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

It should return something like "nnpx yypx".


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

This was almost perfect, The only thing I changed was split('px') so that your able to have the raw number when you use it for other calculations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜