easeOutInQuad返回错误“easeOutQuad”未定义

时间:2013-07-08 03:36:51

标签: jquery animation easing jquery-easing easing-functions

我有一个jQuery动画,最后使用默认的swing缓动减慢太多。我尝试了线性选项,但在接近结束时看起来同样很慢。我经历了尝试here的几个缓动函数。因为我有几个其他动画运行延迟同步它们似乎任何缓和功能与原来的摇摆缓和变化太多会抛出一切不同步。在一些搜索之后,我找到了一个easeOutInQuad函数,其图形看起来像是swing函数的倒数。我认为,与swing函数相反(或接近倒数)的缓动函数不太可能改变运行动画的总时间。这是我的代码中的easeOutInQuad和依赖的easeOutQuad和easeInQuad函数:

            $(function(){$.extend($.easing,{
    easeOutQuad:function(e,f,a,h,g){
        return -h*(f/=g)*(f-2)+a;
    },
    easeInQuad:function(e,f,a,h,g){
        return h*(f/=g)*f+a;
    },
    easeOutInQuad:function(e,f,a,h,g){
        if(f<g/2){
            return easeOutQuad(f*2,a,h/2,g);
        }return easeInQuad((f*2)-g,a+h/2,h/2,g);
    }
});});

出于某种原因,当我运行动画时,我得到一个easeOutQuad是未定义的错误。我对jQuery有些新意。任何帮助表示赞赏。

这里参考的是我正在使用的其余代码:

$(document).ready(function() {
var fC_duration = 10000;
//flyingCrow synchronization *No Edit*
var rW_delay = 0.021*fC_duration;
var uFin_delay = 0.183*fC_duration;
var uFout_delay = 0.025*fC_duration;
var mF_delay = 0.225*fC_duration;
var dF_delay = 0.242*fC_duration;
//bruce2 and and hand FadeOut synchronization *No Edit*
var b2_delay = 0.133*fC_duration;
//synchronize cardGrab with flyingCrow *No Edit*
var fCgC_sync = 0.417*fC_duration;
// Syncs completion of bruce animations with start of flyingCrow
var bFc_sync = fC_duration+3000;
$(function(){$.extend($.easing,{
    easeOutQuad:function(e,f,a,h,g){
        return -h*(f/=g)*(f-2)+a;
    },
    easeInQuad:function(e,f,a,h,g){
        return h*(f/=g)*f+a;
    },
    easeOutInQuad:function(e,f,a,h,g){
        if(f<g/2){
            return easeOutQuad(f*2,a,h/2,g);
        }return easeInQuad((f*2)-g,a+h/2,h/2,g);
    }
});});
// lock scroll position, but retain settings for later
function lockScroll(){
    var html = jQuery('html'); // it would make more sense to apply this to body, but IE7 won't have that
    var scrollPosition = [
    self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
    self.pageYOffset || document.documentElement.scrollTop  || document.body.scrollTop
    ];
    html.data('scroll-position', scrollPosition);
    html.data('previous-overflow', html.css('overflow'));
    html.css('overflow', 'hidden');
    window.scrollTo(scrollPosition[0], scrollPosition[1]);
}
function unlockScroll(){
    // un-lock scroll position
    var html = jQuery('html');
    var scrollPosition = html.data('scroll-position');
    html.css('overflow', html.data('previous-overflow'));
    window.scrollTo(scrollPosition[0], scrollPosition[1]);
}
lockScroll();
$(".bruce").fadeTo(3000, 1, function() {
    $(".question").animate({"opacity": 1}, "fast");
    $(".question").delay(4500).animate({"opacity": 0}, "fast", function() {
        $(".bruce").fadeTo(2500, 0);
        $(".bruce2").delay(1700).fadeTo(50, 1);
        $(".shake").delay(1700).fadeTo(50, 1, function() {
            $(".solution").delay(1600).animate({"opacity": 1}, "fast");
        });
    });
});
setTimeout(function() {
    $(".crowTree").delay(250).animate({"opacity": 0}, 200);
    $(".flyingCrow").delay(350).animate({
        width: "1215px",
        height: "860px",
        marginLeft: "-130%",
        marginTop: "300px"},
        {
        duration: fC_duration,
        queue: false,
        easing:'easeOutInQuad'
    });
    $(".raiseWings").animate({"opacity": 1}, "fast", function () {
        $(".raiseWings").delay(rW_delay).animate({"opacity": 0}, "fast");
    });
    $(".upFlap").delay(uFout_delay).animate({"opacity": 1}, "fast", function() {
        $(".upFlap").delay(uFin_delay).animate({"opacity": 0}, "fast");
    });
    $(".midFlap").delay(mF_delay).animate({"opacity": 1}, "fast", function() {
        $(".midFlap").animate({"opacity": 0}, "fast");
    });
    $(".downFlap").delay(dF_delay).animate({"opacity": 1}, "fast", function() {
        $(".downFlap").animate({"opacity": 0}, 1, function() {
            $(".midFlap").animate({"opacity": 1}, 1, function() {
                $(".midFlap").delay(100).animate({"opacity": 0}, 1, function() {
                    $(".upFlap").animate({"opacity": 1}, 1, function() {
                        $(".solution").animate({"opacity": 0}, "fast");
                    });
                });
            });
        });
    });
    setTimeout(function() {
        $(".upFlap").animate({"opacity": 0}, 1, function() {
            $(".grabCard").animate({"opacity": 1}, 1, function() {
                $(".grabbedCard").animate({"opacity": 0}, 1, function() {
                    $(".hand, .bruce2").fadeTo(b2_delay, 0);
                });
            });
        });
    },fCgC_sync);
    setTimeout(function() {
        unlockScroll();
        $('html, body').animate({scrollTop:$(document).height()}, 2000);
    },fC_duration);
},bFc_sync);

});

1 个答案:

答案 0 :(得分:0)

您的代码......

if(f<g/2){
            return easeOutQuad(f*2,a,h/2,g);
        }return easeInQuad((f*2)-g,a+h/2,h/2,g)

easeOutQuad()无法像这样调用。