Weird behaviour in jscrollpane with scroll event?

90 views Asked by At

api.scrollToY function is running recursively in scroll event only , is there any way to stop it?

 $('.scroll-pane').bind('scroll',function (e) { 
      api.scrollToY(100)
      return false;
 });
1

There are 1 answers

2
Marcos Pérez Gude On

I don't understand, but if you need to listen an event like scroll or resize (that fires tons of times) you can use a debouncer for your function. Underscore library have one very useful. See more:

http://davidwalsh.name/javascript-debounce-function

You can modify easy to change resize to scroll

var myEfficientFn = debounce(function() {
    // All the taxing stuff you do
}, 250);

window.addEventListener('scroll', myEfficientFn);