jQuery: Detect Scroll Up & Scroll Down

addClass, manipulate DOM, do stuff on scroll up or down. Uses Jquery scrollTop on Window.

by Petko Bossakov

HTML

<div>
<div class="fixed">
Bleh
</div>
</div>

CSS

html, body {
    height:300%
}
.fixed {
  margin-top: calc(-50vh + 50%);
}

JavaScript

var position = $(window).scrollTop(); 

// should start at 0

/*
$(window).scroll(function() {
$('.fixed').hide();
    var scroll = $(window).scrollTop();
    $('.fixed').css('margin-top', scroll + 'px');
    $('.fixed').show();
});
*/