我需要在点击灯箱内的链接时滚动到一个段落。我尝试使用下面的代码
function goToByScroll(id) {
$('html,body').animate({scrollTop: $("#"+id).offset().top}, 'slow');
}
这会在后台滚动整个页面,而不是滚动到前面灯箱中的内容。我尝试使用灯箱的 id 而不是 ('html,body') 进行动画处理,但没有运气。有没有办法做到这一点?
最佳答案
您可以通过使用为您的段落提供的 id 来使用类似的东西:
$("#button").click(function() {
$('html, body').animate({
scrollTop: $("#my_paragraph").offset().top
}, 2000);
});
我给你做了个 fiddle here
你必须给你的 anchor id 'button' 和你的段落 id 'my_paragraph' 或任何适合你需要的东西。
希望这可以帮助。
关于javascript - 在 jquery 灯箱中使用 anchor 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33362160/