pazguille/scrolling

A few ideas (do not know if they are usable for others)

Opened this issue · 0 comments

You could probably return the animation frame (or timeout) ID, so that it can be cleared later (maybe we want to ignore quick subsequent scroll events and only fire once):

        requestAnimFrame = (function () {
            return window.requestAnimationFrame ||
                window.webkitRequestAnimationFrame ||
                window.mozRequestAnimationFrame ||
                function (callback) {
                    return window.setTimeout(callback, 1000 / 60);
                };
        }()),
        cancelAnimFrame = (function () {
            return window.cancelAnimationFrame ||
                window.webkitCancelAnimationFrame ||
                window.mozCancelAnimationFrame ||
                function (id) {
                    window.clearTimeout(id);
                };
        }()),

That would mean we should store the ID per element so that we can clear it:

        if (this._collection[el] === undefined) {
            this._collection[el] = {
                'id' : false,
                'listeners': []
            };

So that when the event fires we can clear the previous frame (timeout):

            /**
             * requestAnimationFrame
             */
            if(scroll._collection[scrolledElement].id) {
                cancelAnimFrame(scroll._collection[scrolledElement].id);
            }
            scroll._collection[scrolledElement].id = req...

These are just off the top of my head (sorry if I missed something and this is not a valid idea), also sorry for the bucket of code - if you think this is usable, but the code here is too messy, I can create a pull request.

Cheers!