84669 人學習
152542 人學習
20005 人學習
5487 人學習
7821 人學習
359900 人學習
3350 人學習
180660 人學習
48569 人學習
18603 人學習
40936 人學習
1549 人學習
1183 人學習
32909 人學習
隨著網站頁面的出現,使用捲動作為導航長頁面的方法變得越來越流行。使用JS jQuery程式碼,可以輕鬆地在nav元素中設定連結以捲動到頁面的相應部分。如果你希望在JS不存在時很好地降級,請將錨標記添加到頁面中,本篇文章就來給大家介紹關於使用
下面是具體的程式碼
Coffeescript:
$("nav").find("a").click (e) -> e.preventDefault() section = $(this).attr "href" $("html, body").animate scrollTop: $(section).offset().top
或JS程式碼:
$("nav").find("a").click(function(e) { e.preventDefault(); var section = $(this).attr("href"); $("html, body").animate({ scrollTop: $(section).offset().top }); });
HTML程式碼:
Welcome About Section 3 Welcome to this website About this website, and such The third section
這篇文章到這裡就已經全部結束了,更多精彩內容大家可以關注PHP中文網的HTML影片教學專欄! ! !
以上是使用