2013-05-31 30 views
0

对于包装在jquery对象中的dom元素,我需要获取当前位置或者如果它当前正在动画,我需要改为获取其结束位置。有什么方法可以在jquery.animate()方法中作为properties-argument来访问对象?或者我需要将这些对象存储在某个地方,以便我稍后可以查看给定的dom元素在哪里动画?获取在动画方法中作为属性参数传递的对象

回答

0

想通了如何做这件事的方法:

举例来说,如果我想对一个对象50像素的动画到其当前位置的右侧或地方它会朝我可以这样做:

var currentX=myJqueryObject.css("left");//Get the position it's currently at 
myJqueryObject.finish();//finish the animation so its position instantly gets set to where its animating towards 
var endx=parseInt(myJqueryObject.css("left"));//get its position now. If it wasn't animating when finish() was called then the call didn't change anything. 
myJqueryObject.css("left",currentX);//set its position back to where it was before calling finish() 
myJqueryObject.animate({left:endx+50});//now animate it 50px to the right of its current position or 50px to the right of the position it was animating towards 
0

“animate”方法的标准参数之一是“完整”回调。

里面一个“完整”的功能,你可以通过“本”在像这样选择包装获得当前元素:

$("div").animate({ 
    "width": '500' 
}, 3000, function() { 
    $(this).css({"background-color":"black"}); 
}); 

http://jsfiddle.net/Ana5R/

还有一个在每个步骤中调用的“进度”功能取决于您的需求。

+0

不相当肯定,如果你让我的权利。我确实找出了一个解决方案,但我发布了 – Clox

相关问题