jQuery 缓动弹跳动画
jQuery easing Bounce animation
我正在尝试为动画添加弹跳效果,但无法这样做。我一直在关注jQuery API animate()页面,但我一直失败。我正在尝试创建一种效果,使我的对象从顶部滑入并在安顿到位之前反弹。
$(this).animate( {
"top": "+=100px"
}, {
duration: '400',
specialEasing: {
width: 'linear',
height: 'easeOutBounce'
},
}
);
我不太确定您希望反弹的具体元素,但请尝试以下操作:
$(this).animate({ "top" : "+=100px" }, 400, "easeOutBounce");
这需要jQuery Easing plugin。更多信息,github或CDN。
演示:
$("#target").animate({ "top" : "+=100px" }, 400, "easeOutBounce");
#target{ position:absolute; left:50px; top:50px; background:red; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js"></script>
<div id='target'>Hellow World<div>
要使用 jQuery 实现bounce
缓动效果,您需要扩展有限数量的可用缓动方法并添加更多高级缓动方法。这是一个插件,它提供了许多很酷的缓动功能。
您还可以复制所需的缓动方法(如果您不需要插件带来的所有可能性)并将其合并到代码中的某个位置:
/* jQuery easing */
jQuery.extend( jQuery.easing,{
def: 'easeOutQuad',
easeOutBounce: function (x,t,b,c,d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
}
});
演示:
function bounceDown(){
$('.ball').animate({top:150}, 1000, 'easeOutBounce', onEnd);
}
function onEnd(){
$(this).animate({top:0}, 500, 'easeOutCubic', bounceDown);
}
bounceDown();
.ball{
background:red;
border-radius:50%;
display: inline-block;
padding:30px;
position:relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js"></script>
<div class='ball'></div>
相关文章:
- 如何简化动画jQuery代码
- 如何禁用可排序动画 Jquery
- 离开页面前的动画JQuery
- 动画Jquery弹出菜单
- 设置元素动画jquery
- 如何自动动画jquery画廊
- 缩放/动画 jQuery 拖放到可拖放时可拖动
- 卡片动画Jquery和CSS
- 拆分襟翼文本动画 Jquery
- 满足条件时禁用动画 jQuery
- 传递参数以动画 jquery 函数
- 延迟和动画 jQuery
- 获取动画 jQuery Java 脚本中行进的像素数
- 重新启动动画jquery和javascript
- 为什么这个脚本在页面加载后3秒没有动画(jquery)
- 菜单图标动画jQuery
- 制作无限动画jQuery
- 将延迟应用于动画jquery
- 添加滑动回调动画Jquery
- 使用动画 jquery 更改文本