Ryan Saxe
Ryan Saxe

Reputation: 17829

disable scrolling up past specific point

How can I make it so that a viewer cannot scroll up (past a specific point)?

Making it so a viewer cannot scroll is easy with:

body{
    overflow: hidden;
}

but that disables scrolling down too.

Detailed description

what I want is some javascript/jquery code that will not allow scrolling up past a given parameter, while the viewer can still scroll up and down before that parameter is reached, but after it is reached they can only scroll up as long as it's not scrolling up past the given parameter

I have absolutely no idea how to go about doing this, any ideas?

Upvotes: 1

Views: 3360

Answers (1)

Chad
Chad

Reputation: 5408

You could set a physical point and say something like:

$(function() {
    var scrollPoint = 200;
    var scrolledPast = false;
    $(window).scroll(function() {
        $(window).scrollTop() > scrollPoint ? scrolledPast = true : '';
        $(window).scrollTop() < scrollPoint && scrolledPast == true ? $(window).scrollTop(scrollPoint) : '';
    }).scroll();
});

Fiddle

Although the disabling of scrolling seems a bit counter-intuitive-- why not just hide stuff off the page itself?

Upvotes: 1

Related Questions