No matter what I do I keep getting this error
Error: no element is specified to initialize PerfectScrollbar
same here, but PerfectScrollbar works...
I'm trying to make a custom Vue component using PS, same here. I'm trying to pass the element just like this: scrollBar().initialize(this.$el, this.settings);
I had this error using react-perfect-scrollbar. I eventually found that it was because I was importing just perfect-scrollbar.
I had the same issue turned out that I was trying to create the scrollbar before document ready.
Error: no element is specified to initialize PerfectScrollbar
This error simply means that you are calling PerfectScrollbar on something that doesn't exist!
for example:
var myItems = new PerfectScrollbar("#my-items", {
wheelPropagation: true
});
Will throw that error if there is no element in DOM with id="my-items".
It is necessary to initialize PerfectScrollbar after loading the page _to avoid this error_, in a class use componentDidMount in a function (Hooks) use use effect
// in a class type component :
componentDidMount() {
//To initialise:
const container = document.querySelector('#menuScroll');
const ps = new PerfectScrollbar(container);
}
// in a function type component (similar to componentDidMount and componentDidUpdate) :
useEffect(() => {
//To initialise:
const container = document.querySelector('#menuScroll');
const ps = new PerfectScrollbar(container);
});
Most helpful comment
Error: no element is specified to initialize PerfectScrollbarThis error simply means that you are calling PerfectScrollbar on something that doesn't exist!
for example:
Will throw that error if there is no element in DOM with id="my-items".