在 jquery 灯箱中使用锚点滚动

Scrolling with anchor in jquery lightbox

我需要在灯箱内单击 link 滚动到某个段落。我尝试使用下面的代码

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);
});

我给你做了一个fiddlehere

您必须为您的锚点提供 ID 'button',为您的段落提供 ID 'my_paragraph' 或任何适合您需要的 ID。

希望对您有所帮助。