通過使用 jQuery 中的 animate 和 scrollTop 方法,你無需插件便可創建一個簡單地回到頂部動畫:
// Back to top
$('a.top').click(function (e) {
e.preventDefault();
$(document.body).animate({scrollTop: 0}, 800);
});
<!-- Create an anchor tag -->
<a class="top" href="#">Back to top</a>