简体   繁体   English

jQuery缓动弹跳动画

[英]jQuery easing Bounce animation

I am trying to add a bounce effect to my animation but am having trouble doing so. 我正在尝试给动画添加反弹效果,但是这样做有麻烦。 I have been following the jQuery API animate() page but I keep failing. 我一直在关注jQuery API animate()页面,但一直失败。 I am trying to create an effect where my object slides in from the top and bounces before settling into place. 我正在尝试创建一种效果,使我的对象从顶部滑入并反弹,然后再固定到位。

$(this).animate( {
        "top": "+=100px"
    }, { 
        duration: '400',
        specialEasing: {
            width: 'linear',
            height: 'easeOutBounce'
        },
    }
);

我不确定您希望弹跳什么元素,但​​是请尝试以下操作:

$(this).animate({ "top" : "+=100px" }, 400, "easeOutBounce");

To Achieve a bounce easing effect with jQuery, you would need to extend the limited number of available easing methods and add more advance ones. 要使用jQuery实现bounce缓和效果,您需要扩展有限数量的可用缓和方法,并添加更多高级方法。 Here's a plugin for that which offer many cool easing functions. 这是一个提供许多炫酷缓动功能的插件。

You can also copy the easing method which you need (if you don't need the whole range of possibilities the plugin brings to the table) and incorporate it somewhere in your code: 您还可以复制所需的缓动方法(如果不需要将插件带到表中的全部可能性),并将其合并到代码中的某个位置:

/* 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;
        }
    }
});

Demo: 演示:

 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> 

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

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