Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bind to event other than native scroll #26

Merged
merged 3 commits into from
Nov 18, 2015
Merged

Conversation

sjwilliams
Copy link
Owner

This change gives us the option of monitoring an event other than native scroll to check for updates.

This is useful in cases, like at The New York Times, where we already have a view that is monitoring scroll events and dispatching its own, throttled version of scroll. I'd rather subscribe to these site-wide events than attach an additional handler to the scroll. Here's the exact implementation I'm developing against:

  $container.scrollStory({
    content: $items,
    scrollEvent: function(cb){
      PageManager.on('nyt:page-scroll', cb);
    }
  }).data('plugin_scrollStory');

The new scrollEvent option can be a function that calls the update method as a callback, like the example above, or a string that specifies an event on the window to listen for. The default is the string 'scroll', which gets translated to our current technique, monitoring $(window).scroll() with a throttle determined by scrollSensitivity and throttleType.

If another string is passed in, we monitor the window for that event. Something like this:

// some code dispatching throttled events
$window.trigger('nytg-scroll');

 $container.scrollStory({
   scrollEvent: 'nytg-scroll'
 });

sjwilliams added a commit that referenced this pull request Nov 18, 2015
Bind to event other than native scroll
@sjwilliams sjwilliams merged commit 2ff8991 into master Nov 18, 2015
@sjwilliams sjwilliams deleted the alternate-event branch November 18, 2015 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant