单击显示div并滚动到它 [英] Show div on click and scroll to it
本文介绍了单击显示div并滚动到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个javascript函数,可在单击时显示/隐藏div,我希望页面在show函数中向下滚动到该div.我已经包含了ScrollTop函数,但是它似乎无法正常工作.这是我的代码:
I have a javascript function to show/hide a div on click and I would like the page to scroll down to that div on show function. I have included the ScrollTop function but it doesn't seem to be working. Here is my code:
$('#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.
});
这篇关于单击显示div并滚动到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文