JS自定义缓存函数

function animate(){
    var top = $(document).scrollTop();
    var end = 0;
    var dur = 500;
    var t = 0;
    var ts = setInterval(function(){
        if(t>=dur) clearTimeout(ts);
        tt = Math.ceil(speed(t,top,-(top),dur));
        $(document).scrollTop(tt);
        t+=50;
    },50);
    function speed(t,b,c,d){
        if ((t/=d/2) < 1) return c/2*t*t*t + b;
        return c/2*((t-=2)*t*t + 2) + b;
    }
}

t:当前时间
b:初始值
c:变化值
d:持续时间