mCustomScrollBar:未被捕获的TypeError:$(...).mCustomScrollBar不是窗口调整大小时的函数 [英] mCustomScrollBar: Uncaught TypeError: $(...).mCustomScrollBar is not a function on window resize

查看:225
本文介绍了mCustomScrollBar:未被捕获的TypeError:$(...).mCustomScrollBar不是窗口调整大小时的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to initialise and destroy a mCustomScrollBar scrollbar plugin depending on the window's width (some jquery in an es6 app, traspiled using webpack/babel). However I get an error when resizing the window:

未捕获的TypeError:$(...).mCustomScrollBar不是函数".

"Uncaught TypeError: $(…).mCustomScrollBar is not a function".

这是我的代码:

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();

有人可以指出我要去哪里了吗?

Can someone point out where I m going wrong?

推荐答案

我已经解决了这个问题,以某种方式我的潜意识忘记了Javascript区分大小写...该函数应显示为:

I have solved the problem, somehow my subconscious forgot Javascript was case sensitive... the function should read:

$(scrollPane).mCustomScrollbar();

不是

$(scrollPane).mCustomScrollBar();

smh !!!

这篇关于mCustomScrollBar:未被捕获的TypeError:$(...).mCustomScrollBar不是窗口调整大小时的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆