<html>
<head>
<title>
Complete code to create fixed menu on scroll
</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
h1 {
background-color: #333;
color: #222;
font: bold 80px "arial";
height: 200px;
padding: 25px;
text-align: center;
text-shadow: 0 1px 1px #4d4d4d;
}
p {
margin-top: 25px;
}
.nav-container {
background-color: #f86d5a;
}
.nav {
height: 46px;
border-bottom: 4px solid #222;
}
.nav ul {
list-style: none;
}
.nav ul li {
float: left;
line-height: 46px;
border-right: 2px solid #f56956;
border-left: 2px solid #f9897a;
}
.nav ul li:first-child {
border-left: none;
}
.nav ul li:last-child {
border-right: none;
}
.nav ul li a {
display: block;
text-decoration: none;
color: #333;
font-size: 1.1em;
padding-left: 20px;
padding-right: 20px;
}
.nav ul li a:hover {
background-color: #222;
color: #f86d5a;
}
.fix-nav {
/* this make our menu fixed top */
z-index: 9999;
position: fixed;
left: 0;
top: 0;
width: 100%;
}
.fix-body {
/* this will adjust body top margin to prevent content jumping when nav gets fix */
margin-top: 50px;
}
.content {
width: 80%;
margin: 25px auto;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript">
</script>
<script type="text/javascript">
jQuery("document").ready(function($){
var nav = $('.nav-container');
var pos = nav.offset().top;
$(window).scroll(function () {
var fix = ($(this).scrollTop() > pos) ? true : false;
nav.toggleClass("fix-nav", fix);
$('body').toggleClass("fix-body", fix);
}
);
}
);
</script>
</head>
<body>
<div>
<h1>
Fellow Tuts
</h1>
</div>
<div class="nav-container">
<div class="nav">
<ul>
<li>
<a href="">
Menu I
</a>
</li>
<li>
<a href="">
Menu II
</a>
</li>
<li>
<a href="">
Menu III
</a>
</li>
</ul>
</div>
</div>
<div class="content">
<p>
Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn't listen. She packed her seven versalia, put her initial into the belt and made herself on the way.
</p>
<p>
put more content...
</p>
</div>
</body>
</html>
Thứ Năm, 10 tháng 11, 2016
Code menu trượt theo trình duyệt - CSS & JQuery
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét