스크롤해도 상단에 고정되는 메뉴 만들기 > jquery

본문 바로가기
사이트 내 전체검색

jquery

스크롤해도 상단에 고정되는 메뉴 만들기

페이지 정보

작성자 서방님 댓글 0건 조회 191회 작성일 17-04-17 15:24

본문

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

댓글목록

등록된 댓글이 없습니다.

Total 193건 6 페이지
게시물 검색

회원로그인

접속자집계

오늘
78
어제
84
최대
1,347
전체
154,449
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.