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!!!
Related videos on Youtube
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, 2022Comments
-
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 over 7 yearsMaybe you are not loading the plugin.
-
vicgoyso over 7 yearsIts definitely loading, unless i would receive a 404 error...
-
Felix Kling over 7 yearsNot if you forgot to include the plugin.
-
vicgoyso over 7 yearsIts definitely loading, when I view source and click the link it loads the minified script.
-