我有一个 javascript 函数可以在单击时显示/隐藏一个 div,我希望页面在显示函数时向下滚动到该 div。我包含了 ScrollTop 函数,但它似乎不起作用。这是我的代码:
$('#output').hide();
$('#readMore').click(function(){
$('#output').show(150);
$('#readMore').hide(150);
return false;
$('html, body').scrollTop($('#output').offset().top);
});
$('#readLess').click(function(){
$('#output').hide(150);
$('#readMore').show(150);
});
最佳答案
请把return false;
放在最后。
$('#readMore').click(function(){
$('#output').show(150);
$('#readMore').hide(150);
$('html, body').scrollTop($('#output').offset().top);
return false; // Please put the return false; at the end.
});
关于javascript - 单击显示 div 并滚动到它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13288205/