TypeError:$。debounce不是函数

Dav*_*ton 5 jquery

我正在使用此代码:

function resizeJquerySteps() {
    $('.wizard .content').animate({
        height: $('.body.current').outerHeight()
    }, 'slow');
}

$(window).resize($.debounce(250, resizeJquerySteps));
Run Code Online (Sandbox Code Playgroud)

并收到此错误TypeError: $.debounce is not a function是没有错误的另一种写方法吗?

Evs*_*dim 9

这个函数在像这样的库中定义http://benalman.com/code/projects/jquery-throttle-debounce/jquery.ba-throttle-debounce.js

您需要将此库包含到您的项目中。请参阅此处的示例http://jsfiddle.net/hYsRh/4/

$(window).scroll($.debounce( 250, true, function(){
  $('#scrollMsg').html('SCROLLING!');
} ) );
Run Code Online (Sandbox Code Playgroud)

  • 欢迎提供解决方案的链接,但请确保您的答案在没有它的情况下也有用:[在链接周围添加上下文](//meta.stackexchange.com/a/8259) 这样您的其他用户就会知道它是什么以及为什么它在那里,然后引用您链接到的页面中最相关的部分,以防目标页面不可用。[仅是链接的答案可能会被删除。](//stackoverflow.com/help/deleted-answers) (3认同)