Perfect-scrollbar: Error: no element is specified to initialize PerfectScrollbar

Created on 29 Mar 2018  Â·  6Comments  Â·  Source: mdbootstrap/perfect-scrollbar

No matter what I do I keep getting this error
Error: no element is specified to initialize PerfectScrollbar

Most helpful comment

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".

All 6 comments

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);
  });
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gpluess picture gpluess  Â·  4Comments

chavishindler picture chavishindler  Â·  3Comments

eddieklc picture eddieklc  Â·  3Comments

DevTony picture DevTony  Â·  3Comments

MigFerreira picture MigFerreira  Â·  7Comments