How can I prevent the body from scrolling to the end?

  • 0
    Who knows, please tell me how it is possible in Javascript to prohibit the vertical scrolling of the body to the end, i.e. leave exactly 150 px at the end?
    To prevent the user from seeing the site footer.
    JavaScript Daphne Blevins, Feb 15, 2019

  • 2 Answers
  • 0
    Something like this:

    window.addEventListener('scroll', function() {
    var bottom = document.body.scrollHeight - window.innerHeight - pageYOffset;
    if (bottom < 150) {
    var fix = document.body.scrollHeight - window.innerHeight - 150;
    window.scrollTo(0, fix);
    }
    });


    Not sure if this will work on smartphones, but on PC it should.
    Clare Flowers

  • 0
    Listen for the scroll event, and if it exceeds the value, set your own. The solution will probably work with a jerk, so you need to think about how you can improve it.



    You can try more options from here:

    https://stackoverflow.com/questions/4770025/how-to .. .
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!