jQuery實(shí)現(xiàn)的粘性滾動導(dǎo)航欄效果實(shí)例【附源碼下載】
本文實(shí)例講述了jQuery實(shí)現(xiàn)的粘性滾動導(dǎo)航欄效果。分享給大家供大家參考,具體如下:
粘性滾動是當(dāng)導(dǎo)航在滾動過程中會占粘于瀏覽器上,達(dá)到方便網(wǎng)站頁面瀏覽的效果,也是一種用戶體驗(yàn),下面我們看一下是怎么實(shí)現(xiàn)的:
jQuery的 smint插件,也是一個(gè)導(dǎo)航菜單固定插件。當(dāng)頁滾動時(shí),導(dǎo)航菜單會固定在頂部;當(dāng)點(diǎn)擊菜單時(shí),頁面會平滑的滾動到對應(yīng)的區(qū)域。
兼容性
由于 smint 使用了 position: fixed,所以它不兼容 IE6。適用瀏覽器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.
引入文件
<link href="css/demo.css" rel="external nofollow" rel="stylesheet" type="text/css"> <script src="js/jquery.min.js"></script> <script src="js/jquery.smint.js"></script>
HTML
<body onload="setTimeout(function() { window.scrollTo(0, 1) }, 100);"> <div class="wrap"> <div class="subMenu"> <div class="inner"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="sTop" class="subNavBtn">Home</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="s1" class="subNavBtn">Section 1</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="s2" class="subNavBtn">Section 2</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="s3" class="subNavBtn">Section 3</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="s4" class="subNavBtn">Section 4</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="s5" class="subNavBtn end">Section 5</a> </div> </div> <div class="section sTop"> <div class="inner"></div><br class="clear"> </div> <div class="section s1"> <div class="inner"><h1>Section 1</h1></div> </div> <div class="section s2"> <div class="inner"><h1>Section 2</h1></div> </div> <div class="section s3"> <div class="inner"><h1>Section 3</h1></div> </div> <div class="section s4"> <div class="inner"><h1>Section 4</h1></div> </div> <div class="section s5"> <div class="inner"><h1>Section 5</h1></div> </div> </div> </body>
注意:菜單的外部容器(如上例的 subMenu)需要設(shè)置樣式 position:absolute,并且每個(gè)菜單的 a 標(biāo)簽需要設(shè)置 id,id 的值與下面對應(yīng)區(qū)域的 class 的值一致。
JavaScript
$(function() { $('.subMenu').smint({ scrollSpeed : 1000 }); });
附:完整實(shí)例代碼點(diǎn)擊此處本站下載。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
- jquery實(shí)現(xiàn)點(diǎn)擊變換導(dǎo)航樣式的方法
- Jquery給當(dāng)前頁或者跳轉(zhuǎn)后頁面的導(dǎo)航欄添加選中后樣式的實(shí)例
- jQuery點(diǎn)擊導(dǎo)航欄選中更換樣式的實(shí)現(xiàn)代碼
- jQuery實(shí)現(xiàn)的監(jiān)聽導(dǎo)航滾動置頂狀態(tài)功能示例
- jquery仿京東導(dǎo)航/仿淘寶商城左側(cè)分類導(dǎo)航下拉菜單效果
- jQuery 頂部導(dǎo)航跟隨滾動條滾動固定浮動在頂部
- 基于jquery實(shí)現(xiàn)導(dǎo)航菜單高亮顯示(兩種方法)
- jquery實(shí)現(xiàn)點(diǎn)擊向下展開菜單項(xiàng)(伸縮導(dǎo)航)效果
- jQuery仿京東商城樓梯式導(dǎo)航定位菜單
- jQuery實(shí)現(xiàn)導(dǎo)航樣式布局操作示例【可自定義樣式布局】
相關(guān)文章
jQuery 寫的簡單打字游戲可以提示正確和錯(cuò)誤的次數(shù)
這篇文章主要介紹了使用jQuery寫的簡單打字游戲可以提示正確和錯(cuò)誤的次數(shù),需要的朋友可以參考下2014-07-07日期時(shí)間范圍選擇插件:daterangepicker使用總結(jié)(必看篇)
下面小編就為大家?guī)硪黄掌跁r(shí)間范圍選擇插件:daterangepicker使用總結(jié)(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09jQuery validate插件實(shí)現(xiàn)ajax驗(yàn)證重復(fù)的2種方法
這篇文章主要介紹了jQuery validate插件實(shí)現(xiàn)ajax驗(yàn)證重復(fù)的2種方法,結(jié)合完整實(shí)例形式分析了jQuery validate插件的使用技巧,需要的朋友可以參考下2016-01-01jQuery實(shí)現(xiàn)多級下拉菜單jDropMenu的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)多級下拉菜單jDropMenu的方法,涉及jquery鼠標(biāo)事件及頁面元素遍歷的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08jQuery設(shè)置Easyui校驗(yàn)規(guī)則(推薦)
本文給大家介紹jquery設(shè)置easyui校驗(yàn)規(guī)則的實(shí)現(xiàn)代碼,代碼簡單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-11-11基于jQuery的公告無限循環(huán)滾動實(shí)現(xiàn)代碼
今天看到一個(gè)網(wǎng)站的公告欄一個(gè)小效果,如果有2條公告或以上就有個(gè)滾動效果,特整理下分享給大家2012-05-05