Window Scrolling Event jQuery Plugin
I wrote this plugin because the "scroll" event in a browser window only fires on scroll complete.
I wanted to have the ability to incrementally update other elements on the page during the scroll. This plugin basically watches for window scrolling and fires an event every time the window scroll position changes.
/**
* Nic's superscroll plugin
* uses a loop to monitor for scroll changing and fires if it does
*/
(function ($) {
var _scrollTop = $(window).scrollTop();
setInterval(function (self) {
if ($(window).scrollTop() != _scrollTop) {
_scrollTop = $(window).scrollTop();
$(window).trigger('superscroll', { scrollAmount: _scrollTop });
}
}, Math.floor(1000/30)); //30FPS
})(jQuery);
//usage
$(window).bind('superscroll', function (e, data) {
console.log('hello:' + data.scrollAmount);
});