Home

Awesome

frame-events

The browser is flooding your code with events, which could make your page slow. With this library you only receive the events at 60fps, with requestAnimationFrame.

Useful events would be scroll, resize, touchmove, mousemove and mousewheel.

How to use

FrameEvents.on(window, "scroll", yourHandler);
FrameEvents.off(window, "scroll", yourHandler);
// collect the layout properties...
function dataHandler(ev) {
  return { lastScrollY: window.scrollY }
}

// ...and you will receive them as the second property in your handler
function scrollHandler(ev, data) {
  console.log(data.lastScrollY)
}

FrameEvents.on(window, "scroll", scrollHandler, dataHandler);

For support of older browsers you should include a requestAnimationFrame polyfill.

Available on bower, named frame-events.

Related articles

Changelog