Skip to content

Instantly share code, notes, and snippets.

@mayeaux
Forked from rhyzx/jquery-headroom.css
Created August 20, 2020 04:42
Show Gist options
  • Save mayeaux/5c2ddde10a59788459cf99352a6d7eb1 to your computer and use it in GitHub Desktop.
Save mayeaux/5c2ddde10a59788459cf99352a6d7eb1 to your computer and use it in GitHub Desktop.
jQuery and minimal version of headroom.js http://wicky.nillia.ms/headroom.js/ demo http://jsfiddle.net/JNAQD/1/
.headroom {
position: fixed;
top: 0;
-webkit-transition: top 0.15s;
transition: top 0.15s;
}
.headroom-hidden {
top: -60px;
}
$(function () {
$('.headroom').each(function () {
var $win = $(window)
, $self = $(this)
, isHidden = false
, lastScrollTop = 0
$win.on('scroll', function () {
var scrollTop = $win.scrollTop()
var offset = scrollTop - lastScrollTop
lastScrollTop = scrollTop
// min-offset, min-scroll-top
if (offset > 10 && scrollTop > 200 ) {
if (!isHidden) {
$self.addClass('headroom-hidden')
isHidden = true
}
} else if (offset < -10 || scrollTop < 200) {
if (isHidden) {
$self.removeClass('headroom-hidden')
isHidden = false
}
}
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment