blockVerticalScrollTraverseEvent function

bool blockVerticalScrollTraverseEvent(
  1. Element element,
  2. WheelEvent wheelEvent
)

Blocks a wheelEvent in the vertical direction that traverses the element.

Implementation

bool blockVerticalScrollTraverseEvent(Element element, WheelEvent wheelEvent) {
  var delta = -wheelEvent.deltaY;
  var up = delta > 0;

  var height = element.offset.height;
  var scrollTop = element.scrollTop;
  var scrollHeight = element.scrollHeight;

  var block = false;
  if (!up && -delta > scrollHeight - height - scrollTop) {
    //Scrolling down, but this will take us past the bottom.
    element.scrollTop = scrollHeight;
    block = true;
  } else if (up && delta > scrollTop) {
    //Scrolling up, but this will take us past the top.
    element.scrollTop = 0;
    block = true;
  }

  if (block) {
    wheelEvent.stopPropagation();
    wheelEvent.preventDefault();
  }

  return block;
}