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

Make scroll and wheel events passive #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

gemfarmer
Copy link

@gemfarmer gemfarmer commented Nov 8, 2016

Make the wheel and scroll events passive to unburden the main thread.

I made this fix to address the issues that I'm seeing here: DOI-ONRR/doi-extractives-data#2111

18F/stickyfill has these changes and have significantly reduced lag we were previously seeing. 18F/stickyfill is also a web module, so to test that it is in fact an improvement, you can add it to your dependencies:

{
  "stickyfill": "github:18f/stickyfill"
}

And require it like webmodules/stickyfill allows: require('stickyfill')

@gemfarmer gemfarmer changed the title make scroll and wheel events passive Make scroll and wheel events passive Nov 8, 2016
@@ -371,8 +371,8 @@
updateScrollPos();
initAll();

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that you need to add feature detection for passive events support before applying it to the event listener. Older browsers that don't support it will understand third object argument as truthy capture option.
Here's the snippet you can use borrowed from Modernizr:

var passiveOption = undefined;
try {
  var opts = Object.defineProperty({}, 'passive', {
    get: function() {
      passiveOption = { passive: true };
    }
  });
  window.addEventListener('test', null, opts);
} catch (e) {}
win.addEventListener('scroll', onScroll, passiveOption);
win.addEventListener('wheel', onWheel, passiveOption);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krzksz thanks for the input! I'll test it out on 18F/stickyfill and see if it helps with older browsers!

@kapouer
Copy link

kapouer commented Sep 28, 2018

Note two things:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants