UNPKG

chicago

Version:

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

35 lines (31 loc) 1.12 kB
// @name: Chicago.events.scrollstart // @description: Triggers an event when a user begins 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. scrollstart : { setup: function(data) { var uid = _c.utils.uid('scrollstart'), handler = function(e) { e.type = 'scrollstart.chicago.dom'; _c.$(e.target).trigger('scrollstart', [{ top : _c.$(e.target).scrollTop(), left : _c.$(e.target).scrollLeft(), }]); }; _c.$(this).on('scrollstart', function() { return _c.$(this).off('scroll', handler); }); _c.$(this).on('scrollend', function() { return _c.$(this).on('scroll', handler).data(uid, handler); }); _c.$(this).data('chicago.event.scrollstart.uid', uid); return _c.$(this).on('scroll', handler).data(uid, handler); }, teardown: function() { var uid = _c.$(this).data('chicago.event.scrollstart.uid'); _c.$(this).off('scroll', _c.$(this).data(uid)); _c.$(this).removeData(uid); return _c.$(this).removeData('chicago.event.scrollstart.uid'); } },