我想在新页面上导航到锚点,但我希望页面在顶部加载后立即平滑滚动到相关的锚点。这可以做到吗?
我完全不懂Javascript。
这是我目前用于当前页面内平滑滚动的js代码。 我只需在链接上应用“scroll”类即可。
非常感谢!
<script>
$(function(){
$('.scroll').on('click',function(e) {
e.preventDefault();
$('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top + 'px' }, 1000, 'swing');
});
});
</script>
scrollTop
函数中,例如150 ->...offset().top + 150 + 'px'
- gmo