[기능] 상단에서 메뉴높이가 높고 아래로 스크롤하면 메뉴높이가 줄어듦

https://www.w3schools.com/howto/howto_js_navbar_shrink_scroll.asp 



<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

* {box-sizing: border-box;}


body { 

  margin: 0;

  font-family: Arial, Helvetica, sans-serif;

}


#navbar {

  overflow: hidden;

  background-color: #f1f1f1;

  padding: 90px 10px;

  transition: 0.4s;

  position: fixed;

  width: 100%;

  top: 0;

  z-index: 99;

}


#navbar a {

  float: left;

  color: black;

  text-align: center;

  padding: 12px;

  text-decoration: none;

  font-size: 18px; 

  line-height: 25px;

  border-radius: 4px;

}


#navbar #logo {

  font-size: 35px;

  font-weight: bold;

  transition: 0.4s;

}


#navbar a:hover {

  background-color: #ddd;

  color: black;

}


#navbar a.active {

  background-color: dodgerblue;

  color: white;

}


#navbar-right {

  float: right;

}


@media screen and (max-width: 580px) {

  #navbar {

    padding: 20px 10px !important;

  }

  #navbar a {

    float: none;

    display: block;

    text-align: left;

  }

  #navbar-right {

    float: none;

  }

}

</style>

</head>

<body>


<div id="navbar">

  <a href="#default" id="logo">CompanyLogo</a>

  <div id="navbar-right">

    <a class="active" href="#home">Home</a>

    <a href="#contact">Contact</a>

    <a href="#about">About</a>

  </div>

</div>


<div style="margin-top:210px;padding:15px 15px 2500px;font-size:30px">

  <p><b>This example demonstrates how to shrink a navigation bar when the user starts to scroll the page.</b></p>

  <p>Scroll down this frame to see the effect!</p>

  <p>Scroll to the top to remove the effect.</p>

  <p><b>Note:</b> We have also made the navbar responsive, resize the browser window to see the effect.</p>

  <p>Lorem ipsum dolor dummy text to enable scrolling, sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

</div>


<script>

// When the user scrolls down 80px from the top of the document, resize the navbar's padding and the logo's font size

window.onscroll = function() {scrollFunction()};


function scrollFunction() {

  if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {

    document.getElementById("navbar").style.padding = "30px 10px";

    document.getElementById("logo").style.fontSize = "25px";

  } else {

    document.getElementById("navbar").style.padding = "80px 10px";

    document.getElementById("logo").style.fontSize = "35px";

  }

}

</script>


</body>

</html>


0
0
이 글을 페이스북으로 퍼가기 이 글을 트위터로 퍼가기 이 글을 카카오스토리로 퍼가기 이 글을 밴드로 퍼가기
captcha
자동등록방지 숫자입력

웹개발

번호 제목 글쓴이 날짜 조회수
2 HTML 특수문자 리스트 최고관리자 08-08 1,343
1 유니코드 특수문자 리스트 최고관리자 08-08 1,396