动画完成后,jQuery Animate具有效果"Bounce"吗? [英] JQuery Animate with Effect 'Bounce' after animation is complete?
问题描述
我一直在这里寻找有关此问题的答案,例如Google等,但似乎还不太满意.
I've been hunting around for an answer on here, Google, etc., and can't seem to quite nail this one.
我有一个ID为#pin01的图像.这是我在div内向下移动的地图上的图钉,着陆在地图图像上(请考虑使用Google地图).
I have an image with an ID of #pin01. This is a pin on a map that I have animating down within a div, landing on an image of a map (think Google map).
效果很好的我的JQuery是这样的:
My JQuery, which works just great, is this:
$('#pin01').animate({ opacity: 0}, 0).delay(500);
$('#pin01').animate({ opacity: 1, top: "305px" }, 500);
我的HTML如下:
<img src="images/pin_blue.png" id="pin01" />
动画效果很好,并且图钉逐渐消失,然后恰好落在地图上.我想要的是在距div顶部305像素后反弹,因此,当它在地图上时,它将在末尾产生一点反弹.我以为会用到这种效果:
The animation works great, and the pin fades in, and drops on to the map just fine. What I'd like, is a bounce after it has been positioned 305px from the top of the div, so when it's on the map, it will give a little bounce at the end. I thought I'd use this effect:
$('#pin01').effect("bounce", { direction:'down', times:5 }, 300);
我认为最终代码将如下所示:
I figured the final code would go something like this:
$('#pin01').animate({ opacity: 0}, 0).delay(500);
$('#pin01').animate({ opacity: 1, top: "305px" }, 500);
$('#pin01').effect("bounce", { direction:'down', times:5 }, 300);
这会导致弹跳,但会返回到该图钉的原始起始位置,而不保留305px的移动.我尝试在效果上放一个顶部:效果不佳.
That results in a bounce, but it returns back to the original starting position for the pin, not retaining the 305px movement. I tried placing a top: on the effect, which didn't work.
我尝试过合并,嵌套这些等等,似乎没有任何效果.
I have tried combining, nesting these, etc., nothing seems to be working.
如果有人有其他想法,请很好奇如何使它正常运行.我认为这是一个简单的调整,似乎无法弄清楚.
If anyone has any other thoughts, curious to see how to get this to function properly. I think it's a simple tweak, just can't seem to figure it out.
解决方案
已删除:
$('#pin01').animate({ opacity: 0}, 0).delay(1000);
$('#pin01').animate({ opacity: 1, top: "350px" }, 500);
在下面的答案中都用一行替换了两个:
$('#pin01').show().animate({ top: 305 }, {duration: 1000, easing: 'easeOutBounce'});
解决了一次在地图上弹跳的问题.
Solved the issue of the bounce once on the map.
要添加一些淡入淡出功能,我将其编写如下:
$('#pin01').animate({ opacity: '0' });
$('#pin01').delay(500).show().animate({ top: 305, opacity: '1' }, {duration: 1000, easing: 'easeOutBounce'});
也许有一种更简洁的淡入淡出方法,但这在我的示例中有效.
There may be a cleaner way to do the fade, but this worked for my example.
推荐答案
尝试使用:
$('#pin01').show().animate({ top: 305 }, {duration: 1000, easing: 'easeOutBounce'});
这篇关于动画完成后,jQuery Animate具有效果"Bounce"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!