[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>
<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
댓글목록
등록된 댓글이 없습니다.