[기능] 상단에 메뉴가 보이다가 아래로 스크롤하면 메뉴가 사라지고 상단으로 가면 메뉴가 보임.

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



<!DOCTYPE html>

<html>

<head>

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

<style>

body {

  margin: 0;

  background-color: #f1f1f1;

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

}


#navbar {

  background-color: #333;

  position: fixed;

  top: 0;

  width: 100%;

  display: block;

  transition: top 0.3s;

}


#navbar a {

  float: left;

  display: block;

  color: #f2f2f2;

  text-align: center;

  padding: 15px;

  text-decoration: none;

  font-size: 17px;

}


#navbar a:hover {

  background-color: #ddd;

  color: black;

}

</style>

</head>

<body>


<div id="navbar">

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

  <a href="#news">News</a>

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

</div>


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

  <p><b>This example demonstrates how to hide a navbar when the user starts to scroll the page.</b></p>

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

  <p>Scroll up to show the navbar.</p>

  <p>Lorem ipsum dolor dummy text 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>

  <p>Lorem ipsum dolor dummy text 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>

var prevScrollpos = window.pageYOffset;

window.onscroll = function() {

var currentScrollPos = window.pageYOffset;

  if (prevScrollpos > currentScrollPos) {

    document.getElementById("navbar").style.top = "0";

  } else {

    document.getElementById("navbar").style.top = "-50px";

  }

  prevScrollpos = currentScrollPos;

}

</script>


</body>

</html>


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

웹개발

번호 제목 글쓴이 날짜 조회수
62 [Linux] CentOS postfix 메일서버 설치 및 설정(sendmail 설정) 최고관리자 12-23 1,489
61 [Ubuntu] 인터넷 연결이 안될 때 최고관리자 12-07 1,297
60 [Apache SSL] Ubuntu 인증서(전자서명) 최고관리자 11-24 1,408
59 [Ubuntu] ssl 임시 인증서 준비 및 발급받기 최고관리자 11-23 1,795
58 [Ubuntu] apache2 환경설정 생성기 최고관리자 11-23 3,013
57 [Ubuntu] apache2 설치 최고관리자 11-23 1,312
56 [vi 편집기] 단축키 최고관리자 11-23 1,242
55 [유용한 블로그] ^^.^^ 최고관리자 11-19 1,248
54 [JS] TimelineJS - 시간의 흐름을 네비게이션화 최고관리자 11-19 1,316
53 [JS] 스크롤을 감지하여 사이트의 헤더를 보이거나 숨기기 최고관리자 11-19 1,452
52 [Linux] NAS Mount 최고관리자 11-12 1,267
51 [React] React활용 최고관리자 11-10 1,305
50 [PHP] exec 실행에 대한 응답코드 최고관리자 11-02 1,656
49 [Linux] Shell Script 최고관리자 10-26 1,564
48 [폰트] 폰트 찾기 사이트 최고관리자 10-21 1,367
47 [통신] Socket packet test Program 최고관리자 10-20 1,850
46 [통신] 맥용 Socket Test Program 최고관리자 10-20 1,638
45 [통신] Mac에서 TCP Socket통신 테스트 하기 최고관리자 10-20 2,910
44 [NginX] 504 Gateway Time-out 에러와 해결방법 +1 최고관리자 10-16 24,598
43 [NginX] 설정 최고관리자 10-13 1,579