本文實(shí)例講述了jQuery實(shí)現(xiàn)平滑滾動(dòng)到指定錨點(diǎn)的方法。分享給大家供大家參考。具體如下:
定義好指定的anchor錨點(diǎn),調(diào)用下面的js代碼可以讓頁(yè)面平滑的滾動(dòng)到指定的位置,非常實(shí)用,比如返回頁(yè)面頂部,去往頁(yè)面底部等功能
// HTML:// <h1 id="anchor">Lorem Ipsum</h1>// <p><a href="#anchor" class="topLink">Back to Top</a></p>$(document).ready(function() { $("a.topLink").click(function() { $("html, body").animate({ scrollTop: $($(this).attr("href")).offset().top + "px" }, { duration: 500, easing: "swing" }); return false; });});希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注