$('.course-header').click(function() { $("html, body").animate({scrollTop: 0}, "smooth"); return false; });
The page will scroll to the top of the page when ".course-header" clicked but I also want the page to scroll back to the previous (original) position when ".course-header" is clicked again. What can I do to make it happen?
I have tried to combining ".toggle()" with ".animate()" but it didn't work.
One solution is to declare a variable for tracking the scroll position and use it to return to the previous position on click: