Skip to content

Instantly share code, notes, and snippets.

@uruly
Created August 10, 2018 00:22
Show Gist options
  • Save uruly/d5f4aac8b864d9fde50d970ee08cd099 to your computer and use it in GitHub Desktop.
Save uruly/d5f4aac8b864d9fde50d970ee08cd099 to your computer and use it in GitHub Desktop.
window.onload = function() {
var header = document.querySelector('header');
var headerOffsetY = header.offsetTop;
window.onscroll = function() {
var offsetY = window.pageYOffset;
if (headerOffsetY > offsetY) {
//ここで固定解除( 元々のものに戻す )
header.style.position = 'absolute';
header.style.top = '';
header.style.bottom = '0';
}else {
//ここで固定
header.style.position = 'fixed';
header.style.top = '0';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment