방법 - 스크롤 시 헤더 크기 조정
CSS 및 JavaScript를 사용하여 스크롤 시 헤더를 축소하는 방법을 알아보세요.
스크롤에서 헤더를 축소하는 방법
1단계) HTML 추가:
헤더 생성:
예시
<div id="header">Header</div>
2단계) CSS 추가:
헤더 스타일 지정:
예시
#header {
background-color: #f1f1f1; /* Grey background */
padding: 50px 10px; /* Some padding */
color: black;
text-align: center; /* Centered text */
font-size: 90px; /* Big font
size */
font-weight: bold;
position: fixed; /* Fixed
position - sit on top of the page */
top: 0;
width: 100%;
/* Full width */
transition: 0.2s; /* Add a transition effect (when
scrolling - and font size is decreased) */
}
3단계) 자바스크립트 추가:
예시
// When the user scrolls down 50px from the top of the document, resize the
header's font size
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
if (document.body.scrollTop > 50 ||
document.documentElement.scrollTop > 50) {
document.getElementById("header").style.fontSize = "30px";
} else {
document.getElementById("header").style.fontSize = "90px";
}
}