<div id="wrap">
<div id="header">
<div class="inner">
<span>header</span>
</div>
</div>
<div class="contents">
<span>contents</span>
</div>
</div>
#header{position: fixed; top:0; transition: .2s ease; width: 100%; height: 65px; z-index: 1000; background-color: #333;
.inner{display: flex; align-items: center; justify-content: center; padding: 15px; box-sizing: border-box;
span{display: inline-block; line-height: 32px; font-size: 20px; font-family: 'Noto Sans'; color: #fff;}
}
&.headUp{top: -65px;}
}
.contents{position: absolute; top: 65px; width: 100%; height: 2000px;
display: flex; align-items: center; justify-content: center; background-color: #555;
span{font-size: 30px; font-family: 'Noto Sans'; color: #fff;}
}
#wrap #header {
position: fixed;
top: 0;
transition: .2s ease;
width: 100%;
height: 65px;
z-index: 1000;
background-color: #333;
}
#wrap #header.headUp {
top: -65px;
}
#wrap #header .inner {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
padding: 15px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
#wrap #header .inner span {
display: inline-block;
line-height: 32px;
font-size: 20px;
font-family: 'Noto Sans';
color: #fff;
}
#wrap .contents {
position: absolute;
top: 65px;
width: 100%;
height: 2000px;
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
background-color: #555;
}
#wrap .contents span {
font-size: 30px;
font-family: 'Noto Sans';
color: #fff;
}
$(function() {
var lastScrollTop = 0;
$(window).scroll(function() {
var st = $(this).scrollTop();
if (st > lastScrollTop) {
$('#header').removeClass('headDown').addClass('headUp');
} else {
$('#header').removeClass('headUp').addClass('headDown');
}
lastScrollTop = st;
});
});
아래 주소를 복사하여 다른 곳에 붙여넣으세요.
모바일 환경에서는 코드 결과가 gif로 표시됩니다.
그래도 결과를 볼까요?
(제대로 된 결과를 보려면 노트북 또는 데스크탑에서 실행해주세요.)