Experience-Monks / scroll-manager

A handler for scrolling inside elements with different eases
19 stars 2 forks source link

Add Callback function for when scrolling is complete #1

Closed BrendanNeufeld closed 9 years ago

BrendanNeufeld commented 9 years ago

so something like: scoller.scrollTo(element, offsetToScroll, duration, ease, callback);

You may want to format the scrollTo function to accept an options object and a callback function so you don't have to check for optional params. So something like:

var options = {
element: <some element>,
offsetToScroll: <offset>,
duration: <duration>,
ease: <ease>
}
scoller.scrollTo(options, callback);

This is up to you. But this format is pretty common and is easier to check for optional options and a callback.

BrendanNeufeld commented 9 years ago

I think you could add it here: https://github.com/Jam3/scroll-manager/blob/master/index.js#L51

Something like:

if (elapsedTime < duration) {
              setTimeout(function() {
                  animateScroll(elapsedTime);
              }.bind(this), increment);
          }else{
            if(callback) callback();
          }
mbfassnacht commented 9 years ago

Thanks for the suggestion @BrendanNeufeld added in 1.1.0 :)