How can I add aceleration to this jQuery animation?

廉价感情. 提交于 2019-12-02 03:30:34

Jquery allows for easing, check out the easing plugin.

It would look like this (un tested)

$('#bannerFijo').animate({ bottom: '-15px' }, 1000, nameofeasing, function() {
                $('#bannerFijo').animate({ bottom: '0px' }, 100, nameofeasing);
}); 

Edit: I Created a test page of this not using the easing plugin http://jsfiddle.net/EbJBn/2/

Sparky

You can use any animation "easing" function within jQuery without a plugin. It's discussed in detail in this question I posted a few months ago...

Looking for jQuery easing functions without using a plugin

The thread above contains the jQuery easing functions in the accepted answer as well as a link to more third party easing functions (the 2nd and 3rd links on that page will download the functions).

Looking at the demos here, it seems like easeInCirc fits your description.

Manually add the specific easing function(s) to your <script>...

$.easing.easeInCirc = function (x, t, b, c, d) {
    return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
}

Then you would simply call it from your existing jQuery animate() functions by placing it just after the duration parameter.

$('#bannerFijo').animate({ bottom: '-15px' }, 1000, 'easeInCirc', function() {
                $('#bannerFijo').animate({ bottom: '0px' }, 100, 'easeInCirc');
});

Here is a JSFiddle with the animate() function slowed for illustration.

you mean easing?

Another Idea: why not bring the easing code to your javascript file? Here's my take on it in JsFiddle You may select your desired easing and cut off others, if plugin size is bothering you. Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!