mCustomScrollBar: Uncaught TypeError: $(...).mCustomScrollBar is not a function on window resize

10,812

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

$(scrollPane).mCustomScrollbar();

not

$(scrollPane).mCustomScrollBar();

smh!!!

Share:
10,812

Related videos on Youtube

vicgoyso
Author by

vicgoyso

Passionate about all things web related, great appreciation for creative web design, as well as client and server side technologies.

Updated on June 04, 2022

Comments

  • vicgoyso
    vicgoyso almost 2 years

    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:

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

    Here is my code:

    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?

    • Felix Kling
      Felix Kling over 7 years
      Maybe you are not loading the plugin.
    • vicgoyso
      vicgoyso over 7 years
      Its definitely loading, unless i would receive a 404 error...
    • Felix Kling
      Felix Kling over 7 years
      Not if you forgot to include the plugin.
    • vicgoyso
      vicgoyso over 7 years
      Its definitely loading, when I view source and click the link it loads the minified script.