Most threads I see about shrinking the header when scrolling involves using jQuery animation or something similar. This makes it too obvious and instant, but I'm looking for something gradual:

http://www.kriesi.at/themes/enfold/

This is a good example of it and I'm trying to make something similar:

jQuery(document).ready(function($){
    var $myDiv = $('#logo img');
    var logoHeight = $myDiv.height;
    var stop = false;

    $(window).scroll(function() {
        logoHeight = $myDiv.height;
        var st = $(this).scrollTop();

        if(st >= 50 || logoHeight >= 97){
            stop = true;
        }

        if(!stop){
            $myDiv.height(st);
        }
    }).scroll();
});

Using this jQuery keeping track of scrolling. The problem it that it never stops or just doesn't show up at all. Is there a better method to achieve what I mean?

有帮助吗?

解决方案

The way you are using stop, it can never become false again after you set it true.

Maybe something like:

var stop = (st >= 50 || logoHeight >= 97);

in place of the if and remove the line var stop = false; above.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top