Guest User

Untitled

a guest
Sep 19th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. canScrollElementVertically = (el, direction) => {
  2. if (direction > 0) {
  3. // Down
  4. return ((el.scrollTop + el.offsetHeight) < el.scrollHeight);
  5. } else {
  6. // Up
  7. return (el.scrollTop > 0);
  8. }
  9. };
  10.  
  11.  
  12. document.body.addEventListener("mousewheel", e => {
  13. let composed = e.composedPath();
  14. const bodyPosition = composed.indexOf(document.body);
  15. if (bodyPosition != -1) {
  16. composed = composed.slice(0, bodyPosition);
  17. }
  18. if (e.deltaY && !composed.find(el => canScrollElementVertically(el, e.deltaY)))
  19. e.preventDefault();
  20. });
Add Comment
Please, Sign In to add comment