用jQuery实现网页卷轴的效果
生活随笔
收集整理的這篇文章主要介紹了
用jQuery实现网页卷轴的效果
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
用jQuery實(shí)現(xiàn)網(wǎng)頁(yè)卷軸的效果:http://www.56mp.cn/UPLOAD/SmoothPageScroll/ jQuery有能力做出這樣的動(dòng)畫滾動(dòng),利用其動(dòng)畫功能和“ scrollTop ”參數(shù)。 最好的處理方法是在您的網(wǎng)頁(yè)上設(shè)置滾動(dòng)指標(biāo)散列標(biāo)記的鏈接(如 #about)。您設(shè)置的“href” 的錨鏈指向鏈接“#target”,然后鏈接會(huì)跳轉(zhuǎn)到網(wǎng)頁(yè)元素在該網(wǎng)頁(yè)上的“target”作為其編號(hào)。這意味著它將不論已啟用JavaScript或不啟用都能動(dòng)行。 以下是代碼: $(function(){ $('a[href*=#]').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) { var targetOffset = $target.offset().top; $('html,body').animate({scrollTop: targetOffset}, 1000); return false;} } }); });
轉(zhuǎn)載于:https://www.cnblogs.com/zhangji/archive/2010/09/08/1821624.html
總結(jié)
以上是生活随笔為你收集整理的用jQuery实现网页卷轴的效果的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 求一个整数n对16求商和余数
- 下一篇: 在Visual Studio 2005中