Detect scroll direction with plain JavaScript

var position = document.documentElement.scrollTop;

document.addEventListener('scroll', function() {
  var scroll = document.documentElement.scrollTop;

  if (scroll > position) {
    console.log('down');
  } else {
    console.log('up');
  }
  
  position = scroll;
});