Skip to content

Instantly share code, notes, and snippets.

@alim-nagoev
Created August 30, 2018 12:55
Show Gist options
  • Save alim-nagoev/d1b6782fd04c0e824af07383fa057bbf to your computer and use it in GitHub Desktop.
Save alim-nagoev/d1b6782fd04c0e824af07383fa057bbf to your computer and use it in GitHub Desktop.
```js
var prevScrollpos = window.pageYOffset;
window.onscroll = function () {
var currentScrollPos = window.pageYOffset;
if (prevScrollpos > currentScrollPos) {
document.querySelector(".header").style.top = "0";
} else {
document.querySelector(".header").style.top = "-90px";
}
prevScrollpos = currentScrollPos;
}
```
```css
.header {
position: fixed;
transition: top 0.3s ease;
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment