UNPKG

chicago

Version:

A front-end JavaScript library for user-interface developers.

42 lines (36 loc) 1.17 kB
// @name: Chicago.events.scrollend // @description: Triggers an event when a user stops scrolling // @since: 1.0.0-beta // @todo: Add `properties` as a default option to list of values // @todo: Value would be array of animation-properties (as strings) to listen for. scrollend : { latency : 150, setup : function(data) { data = _c.$.extend({ latency : _c.$.event.special.scrollend.latency }, data); var uid = _c.utils.uid('scrollend'), timer = null, handler = function(e) { if(timer) { win.clearTimeout(timer); } timer = win.setTimeout(function() { timer = null; var target = _c.$(e.target); return target.trigger('scrollend', [{ top : target.scrollTop(), left : target.scrollLeft(), }]); }, data.latency); }; _c.$(this).data('chicago.event.scrolltop.uid', uid); return _c.$(this).on('scroll', _c.utils.debounce(handler, 100)).data(uid, handler); }, teardown : function() { var uid = _c.$(this).data('chicago.event.scrolltop.uid'); _c.$(this).off('scroll', _c.$(this).data(uid)); _c.$(this).removeData(uid); return _c.$(this).removeData('chicago.event.scrolltop.uid'); } },