【问题标题】:mCustomScrollBar: Uncaught TypeError: $(...).mCustomScrollBar is not a function on window resizemCustomScrollBar: Uncaught TypeError: $(...).mCustomScrollBar is not a function on window resize
【发布时间】:2016-12-24 02:08:12
【问题描述】:

我正在尝试根据窗口的宽度初始化和销毁​​ mCustomScrollBar 滚动条插件(es6 应用程序中的一些 jquery,使用 webpack/babel 进行转换)。但是在调整窗口大小时出现错误:

“未捕获的 TypeError:$(…).mCustomScrollBar 不是函数”。

这是我的代码:

function initCustomScrollbar() {
    var scrollPane = document.querySelector(".scroll-content");
    var scrollPaneInit = $(scrollPane).mCustomScrollbar();

    setTimeout(function () {
        var scrollInnerPane = $(scrollPane).find(".mCustomScrollBox");
        $(scrollInnerPane).height(window.innerHeight + "px");
    }, 500);

    $(window).resize(function () {
        if (window.innerWidth < 768) {
            initCustomScrollbar();
        } else {
            $(scrollPane).mCustomScrollBar('destroy');
        }
    });
}

initCustomScrollbar();

谁能指出我哪里出错了?

【问题讨论】:

  • 可能你没有加载插件。
  • 它肯定正在加载,除非我会收到 404 错误...
  • 如果您忘记包含插件则不会。
  • 它肯定在加载,当我查看源代码并单击链接时,它会加载缩小的脚本。

标签: javascript jquery jquery-plugins ecmascript-6


【解决方案1】:

我已经解决了这个问题,不知何故我的潜意识忘记了 Javascript 是区分大小写的......函数应该是:

$(scrollPane).mCustomScrollbar();

不是

$(scrollPane).mCustomScrollBar();

嘘!!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    • 2021-12-16
    • 2018-04-20
    • 2017-04-13
    • 2015-01-14
    相关资源
    最近更新 更多