I've implemented a JQuery code on my website that allows the page to scroll to the top when clicking on a div with the class of .bottom. The code is working perfectly fine, here it is:
function scrollToTop(){
$('.bottom').click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, 500);
});
Now, I want to add functionality so that when clicking on the .bottom div again, the page scrolls back to the bottom (returning to the initial position).
I attempted to modify the code for this purpose but encountered a bug:
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);
});
}
});
}
Could someone assist me with this issue? Your help will be greatly appreciated.