jQuery 动画向上
我有一个问题,我有一个绝对定位的 div,我想将它设置为向上离开页面的动画(我正在设置一个人跳出屏幕的动画)。
但是,我需要元素位于底部:0,但是当我希望动画完成时,我希望图像具有顶部:-600px。
当我写入时,
$("#jumper").animate({
top: "-600px"
}, 2000, 'easeInBack' );
它将 top top 设置为 0,然后开始动画。
也许有一种方法可以获取元素的 ypos 并在窗口加载时使用 jQuery.css() 设置顶部?
我应该在这里做什么?
I have an issue where I have a div that is positioned absoutely and I want to animate it off the page upwards (I'm animating a person jumping off the screen).
However, I need the element to be bottom: 0, but when I want the animation to finish I want the image to have top: -600px.
When I write
$("#jumper").animate({
top: "-600px"
}, 2000, 'easeInBack' );
it sets top top to 0 and then starts the animation.
Perhaps there is a way to get the ypos of the element and set top with jQuery.css() on window load?
What should I do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只为
bottom
属性设置动画怎么样?您可以获取文档的高度,然后添加600
。http://jsfiddle.net/kavY4/
否则,您会遇到浏览器特定的问题,其中
top
被计算为auto
,并且动画尝试从该位置开始(我猜最终为 0)。要实现此功能,您必须在制作动画之前获取
#jumper
的顶部位置并手动将top
属性设置为该值。编辑:第二个示例也需要将
bottom
设置为auto
。http://jsfiddle.net/kavY4/1/
How about just animating the
bottom
property? You could get the height of the document, then add600
to it.http://jsfiddle.net/kavY4/
Otherwise, you run into browser specific issues where the
top
is calculated to beauto
, and the animation tries to start from that position (which ends up being 0, I guess).To make that work you would have to get the top position of
#jumper
and set thetop
property to that value manually before you animate.EDIT: The second example required
bottom
to be set toauto
as well.http://jsfiddle.net/kavY4/1/
这是您的代码的示例: http://www.jsfiddle.net/fJKah/
看起来按照我的预期工作。也许有其他东西在干扰..
Here is an example with your code : http://www.jsfiddle.net/fJKah/
looks to work as expected to me. maybe something else is interfering ..