http://www.littlestonegroup.org
如果您单击“学习”,我希望它向下滚动到下一个链接。我可以让它捕捉到使用 anchor 链接,但我想要有滚动效果。我看过很多教程,但我不确定如何安装 javascript,也不知道如何实现教程建议的脚本。
提前致谢,非常感谢您的帮助!
最佳答案
我在 CSS-Tricks 发现了这个平滑滚动功能:
$(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;
}
}
});
});
这是正在运行的函数 JSFiddle
您可以通过将上述函数包装在以下内容中将其添加到结束正文标记之前:
<script type="text/javascript">
function here
</script>
关于javascript - 如何使用 javascript 制作从链接到 anchor 的滚动动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25028221/