2016-12-04 117 views
-1

我的頁面底部有一個箭頭鏈接到頁面的頂部,我希望它慢慢向上移動。我認爲這將通過轉換或改造加入。如何將過渡效果添加到頁面頂部的鏈接? HTML和CSS

+0

Hi Kayla,謝謝你的提問。如果您發佈了一些代碼,並且描述了您已經嘗試解決問題的方式以及您遇到了哪些問題,那麼您可能會得到很好的答案。 –

回答

0

平滑滾動是你正在尋找的,但它不能用HTML或CSS來完成。這裏有一個jQuery腳本來完成它:

$(function() { 
    $('a[href*="#"]:not([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) { 
     $('html, body').animate({ 
      scrollTop: target.offset().top 
     }, 1000); 
     return false; 
     } 
    } 
    }); 
}); 

現在只是讓你的箭頭的東西,如「#top返回」爲href值的錨鏈接,並在頁面的頂部添加ID =「頂」的元素。

腳本中的「1000」在滾動動畫期間爲毫秒(在本例中爲1秒)。如果您需要更長時間的滾動,請調整此項。

相關問題