【发布时间】:2014-10-24 19:20:20
【问题描述】:
我在我的网站上使用 Jquery 代码。单击 div (.bottom) 时,我的页面会滚动到顶部。它工作得很好,这是我的代码:
function scroll_cartouche(){
$('.bottom').click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, 500);
});
现在我的页面已经滚动到顶部,我想在再次单击 .bottom div 时滚动到底部(返回初始位置)
这是我尝试过的代码,但我有一个错误:
function scroll_cartouche(){
$(window).scroll(function () {
if ($(this).scrollTop() != 0) {
$('.bottom').click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, 500);
});
} else {
$('.bottom').click(function() {
$("html, body").animate({ scrollTop: 0 }, 500);
});
}
});
}
谁能帮我解决这个问题? 非常感谢,
【问题讨论】:
标签: javascript jquery css jquery-animate scrolltop