我在我的网站上使用Jquery代码。当单击div(.bottom)时,我的页面会滚动到顶部。它运行得很好,这是我的代码:
function scroll_cartouche(){
$('.bottom').click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, 500);
});
现在我的页面已经从上到上滚动了,我希望当再次点击底部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);
});
}
});
}
有人能帮我吗?非常感谢
执行类似的操作
$('.bottom').click(function() {
if ($(window).scrollTop() == 0) {
$("html, body").animate({ scrollTop: $(document).height() }, 500);
} else {
$("html, body").animate({ scrollTop: 0 }, 500);
}
});