window.requestAnimationFrame = window.requestAnimationFrame || function (fn) { return setTimeout(fn, 1000 / 60); }; var target = document.getElementById("plist").offsetTop; if (location.href.indexOf('#plist') > 0 && parseInt(target) > 0) { (function animation() { var init = 0; (function fn() { init += 40; if (init >= target) { init = target; } else { requestAnimationFrame(fn); } document.body.scrollTop = document.documentElement.scrollTop = init; })(); })(); }
本文介绍了一种使用JavaScript实现的平滑滚动效果,当URL包含特定锚点时,页面会以动画形式滚动到该元素位置。通过requestAnimationFrame或setTimeout实现,确保了滚动的流畅性和用户体验。
2249

被折叠的 条评论
为什么被折叠?



