[jQuery] 상단에 메뉴 고정하기 > 팁앤테크

본문 바로가기

사이트 내 전체검색

뒤로가기 팁앤테크

[jQuery] 상단에 메뉴 고정하기

본문

<!doctype html>
<html lang="ko">
  <head>
    <meta charset="utf-8">
    <title>Fixed Header</title>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
      .header {
        text-align: center;
      }
      .jq_menu {
        text-align: center;
        background: #000000;
        padding: 10px 0px;
        width: 100%;
        z-index:99;
        position:relative;
      }
      .wrapper {
        min-height: 500px;
      }
      .jq_fixed {
        position: fixed;
        top: 0px;
      }
    </style>
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
    <script>
      $( document ).ready( function() {
        var jbOffset = $( '.jq_menu' ).offset();
        $( window ).scroll( function() {
          if ( $( document ).scrollTop() > jbOffset.top ) {
            $( '.jq_menu' ).addClass( 'jq_fixed' );
          }
          else {
            $( '.jq_menu' ).removeClass( 'jq_fixed' );
          }
        });
      } );
    </script>
  </head>
  <body>
    <div class="header">
      <h1>Site Title</h1>
    </div>
    <div class="jq_menu">
      <p>
        First Menu
        Second Menu
        Third Menu
        Fourth Menu
      </p>
    </div>
    <div class="wrapper">
    </div>
  </body>
</html>
추천0

댓글목록 0

등록된 댓글이 없습니다.

전체 825건 4 페이지
게시물 검색
Copyright (c) 株式会社YHPLUS. All rights reserved.

사이트 정보

株式会社YHPLUS / 대표 : ZERO
〒171-0014 東京都豊島区池袋2-41-5 アーバン154 8F
050-5539-7787
오픈카카오톡 (YHPLUS) :
https://open.kakao.com/o/slfDj15d

PC 버전으로 보기