Suraj Rawat
Suraj Rawat

Reputation: 3763

Weird behaviour in jscrollpane with scroll event?

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;
 });

Upvotes: 0

Views: 90

Answers (1)

Marcos Pérez Gude
Marcos Pérez Gude

Reputation: 22158

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);

Upvotes: 0

Related Questions