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

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
자동등록방지 숫자입력

웹개발

번호 제목 글쓴이 날짜 조회수
82 [PHP] empty vs is_null vs is_set 비교 최고관리자 09-11 1,265
81 [Font] Every Font Awesome 4.7.0 Icon, CSS Class, & Unicode 최고관리자 08-19 1,304
80 [PHP] 문자열을 구분자로 구분하여 배열로 만들때 whitespace trim시키기 최고관리자 07-29 1,276
79 [PHP] $_SERVER['SERVER_NAME'] vs $_SERVER['HTTP_HOST'] 최고관리자 07-23 1,604
78 [css] Layout을 제대로 하고 싶다면 Flex 와 Grid를 배워보자 최고관리자 07-20 1,705
77 [PHP] define 중복으로 인한 Internal Server Error 500 최고관리자 07-16 1,222
76 [MySQL] Procedure & View 확인 최고관리자 05-25 1,221
75 [JavaScript] JQuery를 이용한 Drag Drop 리스트 순서변경 최고관리자 05-21 2,949
74 [JavaScript] defer 와 async 최고관리자 05-14 1,288
73 [JavaScript] 홈페이지에 날개를 달자 -2 최고관리자 04-26 1,235
72 [HTML] URL 사용 규칙 최고관리자 03-30 1,288
71 [JS] 자바스크립트 쿠키 클래스 최고관리자 03-19 1,315
70 [MySql] mysql error 메세지 모음 최고관리자 03-11 2,990
69 [PHP] TCP Socket Server +2 최고관리자 03-05 3,139
68 [JS] 문자열로 전송된 함수명을 실행하는 방법 최고관리자 02-26 1,698
67 [Javascript] 홈페이지에 날개를 달자 - Animation & Scrolll 효과 Plugin 최고관리자 02-21 1,248
66 [Form] Submit 버턴 만들어 입력데이타 검사하고 Submit 하기. 최고관리자 01-13 1,259
65 [MySQL] Join 걸어서 Update하기 최고관리자 01-07 1,375
64 [Docker] MedDream DICOM Viewer for Orthanc PACS server 최고관리자 01-05 1,861
63 [Docker] 도커 도메인 여러개 사용하기 (Docker multi Domain) (웹서버 여러개) 최고관리자 01-05 5,988