jquery實(shí)現(xiàn)網(wǎng)頁的頁面平滑滾動效果代碼
本文實(shí)例講述了jquery實(shí)現(xiàn)網(wǎng)頁的頁面平滑滾動效果代碼。分享給大家供大家參考,具體如下:
這款網(wǎng)頁頁面平滑滾動jquery代碼,點(diǎn)擊鏈接會讓網(wǎng)頁平滑滾動到鏈接對應(yīng)的位置。
運(yùn)行效果截圖如下:
在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-link-scroll-page-codes/
具體代碼如下:
<!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>頁面平滑滾動jquery代碼</title> <script type="text/javascript" src="jquery1.3.2.js"></script> <script type="text/javascript"> (function($){ $.extend($.fn,{ scrollTo:function(time,to){ time=time||800; to=to||1; $('a[href*=#]', this).click(function(){ if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { var $target = $(this.hash); $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']'); if ($target.length) { if (to == 1) { $('html,body').animate({ scrollTop: $target.offset().top }, time); } else if(to==2){ $('html,body').animate({ scrollLeft: $target.offset().left }, time); }else{ alert('argument error'); } return false; } } }); } }); })(jQuery); </script> <script type="text/javascript" language="javascript"> $(function(){ // $("#a111").scrollTo(600,2妯悜) $("#a111").scrollTo(700) });</script> <style type="text/css" > html{ _overflow:hidden} body {margin:0; height:100%; overflow-y:auto} #a111 { position:fixed; width:1000px; left:10%;} * html #a111 {position:absolute;} #a111 a{ display:block; width:50px; height:20px; background:#000; color:#fff; float:left;} #a111 a:hover{ background:#f60;} #b11{ height:1000px; background:#090;} #b22{ height:1000px; background:#fc0;} #b33{ height:1000px; background:#09d;} </style> </head> <body> <div id="a111"> <a href="#b11">mao1</a> <a href="#b22">mao2</a> <a href="#b33">mao3</a> </div> <div id="b11">網(wǎng)頁1</div> <div id="b22">網(wǎng)頁2</div> <div id="b33">網(wǎng)頁3</div> </body> </html>
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery操作dom實(shí)現(xiàn)彈出頁面遮罩層(web端和移動端阻止遮罩層的滑動)
- jQuery實(shí)現(xiàn)滑動頁面固定頂部顯示(可根據(jù)顯示位置消失與替換)
- JQuery實(shí)現(xiàn)鼠標(biāo)滾輪滑動到頁面節(jié)點(diǎn)
- jQuery的Scrollify插件實(shí)現(xiàn)滑動到頁面下一節(jié)點(diǎn)
- JQuery 實(shí)現(xiàn)在同一頁面錨點(diǎn)鏈接之間的平滑滾動
- jQuery創(chuàng)建平滑的頁面滾動(頂部或底部)
- 基于jquery的從一個頁面跳轉(zhuǎn)到另一個頁面的指定位置的實(shí)現(xiàn)代碼(帶平滑移動的效果)
- jQuery實(shí)現(xiàn)彈窗下底部頁面禁止滑動效果
相關(guān)文章
jQuery easyui datagird編輯行刪除行功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了jQuery easyui datagird編輯行刪除行功能的實(shí)現(xiàn)代碼,需要的朋友可以參考下2018-09-09jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊處心形漂浮的炫酷效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊處心形漂浮的炫酷效果,涉及jQuery事件響應(yīng)及頁面元素屬性動態(tài)變換相關(guān)操作技巧,需要的朋友可以參考下2018-04-04Jquery實(shí)現(xiàn)無縫向上循環(huán)滾動列表的特效
今天小編就為大家分享一篇關(guān)于Jquery實(shí)現(xiàn)無縫向上循環(huán)滾動列表的特效,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-02-02jQuery+CSS3實(shí)現(xiàn)四種應(yīng)用廣泛的導(dǎo)航條制作實(shí)例詳解
這篇文章主要介紹了jQuery+CSS3實(shí)現(xiàn)多種類型的導(dǎo)航條制作實(shí)例詳解的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-09-09jQuery常用樣式操作實(shí)例分析(獲取、設(shè)置、追加、刪除、判斷等)
這篇文章主要介紹了jQuery常用樣式操作,結(jié)合實(shí)例形式分析了jQuery針對頁面元素樣式的獲取、設(shè)置、追加、刪除、判斷等操作方法,需要的朋友可以參考下2016-09-09jquery+CSS3實(shí)現(xiàn)3D拖拽相冊效果
這篇文章主要為大家詳細(xì)介紹了jquery+CSS3實(shí)現(xiàn)3D拖拽相冊效果的具體代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-07-07Jquery Easyui日歷組件Calender使用詳解(23)
這篇文章主要為大家詳細(xì)介紹了Jquery Easyui日歷組件Calender的使用方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12