Hiding content while scrolling up the page

Sometimes you will need a div to be visible only at the bottom of the view port like a link saying More about us which if the user clicks on it, the page will be scrolled up to let him read more details about the site,
but if the user is already scrolling down to the detailed content, then we need to smoothly hide the More about us link, like what we did in Jidari’s landing page (this scenario is only for resolutions lower than 1024px) like this:
enter image description here

So we made our simple jquery plugin:

jQuery.fn.hideWhileScrollingUp = function (options) {
    var element = this;
    var defaults = {
        speed: 3, // 1 is the slowest
        allowedHeightFromBottom: 200 // after these pixels, it will start to disappear gradually based on the speed
    options = $.extend({}, defaults, options);
    $(window).scroll(function () {
        var elementHeightFromBottom = $(window).scrollTop() + $(window).height() - element.offset().top;
        var delta = elementHeightFromBottom - options.allowedHeightFromBottom;
        var opacity = 1 - (delta / $(window).height() * options.speed);
        element.css("opacity", opacity);

and used it like this:


& it is easy to override its defaults also:

    speed: 2

if you wanna try it online, here is the jsfiddle demo for it.

One thought on “Hiding content while scrolling up the page

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s