jquery實(shí)現(xiàn)固定頂部導(dǎo)航效果(仿蘑菇街)
更新時間:2013年03月21日 15:27:20 作者:
蘑菇街導(dǎo)航固定頂部的效果想必大伙有所關(guān)注吧,想實(shí)現(xiàn)吧,本文將帶你走完實(shí)現(xiàn)之旅,接下來的代碼是使用jquery,感興趣的各位可不要錯過了哈
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標(biāo)題文檔</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var headHeight=$(".header").height()+10;
var nav=$(".nav");
$(window).scroll(function(){
if($(this).scrollTop()>headHeight){
nav.addClass("navFix");
}
else{
nav.removeClass("navFix");
}
})
})
</script>
<style type="text/css">
*{ margin:0; padding:0;}
body{ _background-attachment:fixed; _background-image:url(about:blank);} //實(shí)現(xiàn)ie6不支持fixed方法
.header{ width:1000px; height:60px; margin:0 auto; text-align:center;}
.nav{ border:1px solid #ccc; border-radius:5px; overflow:hidden; height:30px; width:1000px; margin:10px auto; background:#fff;}
.nav li{ float:left; padding:0 10px; height:30px; line-height:30px;}
.nav li a{ text-decoration:none; color:#0CF;}
.nav li a:hover{ color:#000; text-decoration:underline;}
.nav ul{ list-style:none;}
.navFix{ position:fixed; left:0; top:0; _position:absolute; top:expression((offsetParent.scrollTop)+0); z-index:2;} //實(shí)現(xiàn)ie6不支持fixed方法
.content{ width:1000px; margin:10px auto;}
</style>
</head>
<body>
<div class="header">
<h1>導(dǎo)航固定在頁面頂部測試</h1>
</div>
<div class="nav">
<ul>
<li><a href="">首頁</a></li>
<li><a href="">藍(lán)楓前端</a></li>
<li><a href="">藍(lán)楓前端</a></li>
<li><a href="">藍(lán)楓前端</a></li>
<li><a href="">藍(lán)楓前端</a></li>
<li><a href="">藍(lán)楓前端</a></li>
<li><a href="">藍(lán)楓前端</a></li>
<li><a href="">藍(lán)楓前端</a></li>
</ul>
</div>
<div class="content">
<p>11111</p>
<p>11111</p>
<p>11111</p><p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
<p>11111</p>
</div>
</body>
</html>
您可能感興趣的文章:
- jquery 面包屑導(dǎo)航 具體實(shí)現(xiàn)
- jquery實(shí)現(xiàn)點(diǎn)擊變換導(dǎo)航樣式的方法
- jquery仿京東導(dǎo)航/仿淘寶商城左側(cè)分類導(dǎo)航下拉菜單效果
- JQuery實(shí)現(xiàn)鼠標(biāo)滑過顯示導(dǎo)航下拉列表
- 簡單的jquery左側(cè)導(dǎo)航欄和頁面選中效果
- JQuery 浮動導(dǎo)航欄實(shí)現(xiàn)代碼
- jQuery 頂部導(dǎo)航跟隨滾動條滾動固定浮動在頂部
- 基于jquery實(shí)現(xiàn)導(dǎo)航菜單高亮顯示(兩種方法)
- jQuery 實(shí)現(xiàn)側(cè)邊浮動導(dǎo)航菜單效果
- jQuery實(shí)現(xiàn)電梯導(dǎo)航模塊
相關(guān)文章
JQuery實(shí)現(xiàn)鼠標(biāo)移動圖片顯示描述層的方法
這篇文章主要介紹了JQuery實(shí)現(xiàn)鼠標(biāo)移動圖片顯示描述層的方法,涉及jQuery鼠標(biāo)事件及動畫效果的使用技巧,需要的朋友可以參考下2015-06-06
jQuery+CSS 實(shí)現(xiàn)的超Sexy下拉菜單
早前發(fā)現(xiàn)了 Soh Tanaka 分享的非常 Sexy 的 Drop Down Menu w/ jQuery & CSS,稍作修改實(shí)現(xiàn)了多級下拉,并實(shí)現(xiàn)了 ASP.NET 中通過輸出 HTML 動態(tài)創(chuàng)建版本,有興趣的童鞋可以包裝成 Server Control。2010-01-01
jquery實(shí)現(xiàn)鼠標(biāo)滑過小圖查看大圖的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)鼠標(biāo)滑過小圖查看大圖的方法,涉及jquery鼠標(biāo)事件及圖片樣式動態(tài)操作的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
jQuery簡單實(shí)現(xiàn)對數(shù)組去重及排序操作實(shí)例
這篇文章主要介紹了jQuery簡單實(shí)現(xiàn)對數(shù)組去重及排序操作,結(jié)合實(shí)例形式分析了jQuery中unique方法進(jìn)行數(shù)組去重及sort方法排序的相關(guān)操作技巧,需要的朋友可以參考下2017-10-10
jquery與js實(shí)現(xiàn)全選功能的區(qū)別
這篇文章主要介紹了jquery與js實(shí)現(xiàn)全選功能的區(qū)別,需要的朋友可以參考下2017-06-06
jQuery.event兼容各瀏覽器的event詳細(xì)解析
jQuery在遵循W3C規(guī)范的情況下,對事件的常用屬性進(jìn)行了封裝,使得事件處理在各大瀏覽器下都可以正常的運(yùn)行而不需要進(jìn)行瀏覽器類型判斷2013-12-12
IE中jquery.form中ajax提交沒反應(yīng)解決方法分享
用jquery form插件,進(jìn)行ajax提交,本來可以用,好好地,突然發(fā)現(xiàn),firefox,opera等可以提交,ie的success函數(shù)運(yùn)行了2012-09-09
jQuery實(shí)現(xiàn)響應(yīng)鼠標(biāo)背景變化的動態(tài)菜單效果代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)響應(yīng)鼠標(biāo)背景變化的動態(tài)菜單效果代碼,涉及jquery鼠標(biāo)mouseover事件操作頁面元素屬性的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08

