简体   繁体   English

在jQuery Animate中获得位置

[英]Getting Position in jQuery Animate

I am animating one image(ie)scaling a image like 我正在对一个图像进行动画处理,即像

$('#img').animate({height:'300px','width':'20px'},2000);

i need to get the current height of the image during the animation. 我需要在动画过程中获取图像的当前高度。 i tried step property. 我尝试了步骤属性。 But its printing so many points which is unrelated to animation. 但是它的印刷点很多,这与动画无关。

Any Idea 任何想法

There's a step option in the animate function that allows for callbacks during the animation. 动画函数中有一个step选项,允许在动画过程中进行回调。 In that callback you can request the position and do what you want with it. 在该回调中,您可以请求该职位并对其进行所需的操作。

http://jsfiddle.net/aYVUE/ http://jsfiddle.net/aYVUE/

var pos = $('#img').position();
alert(pos.top + ', ' + pos.left);

See this link. 请参阅链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM