0

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?

4

1 回答 1

1

您使用的方式stop,将其设置为 true 后,它永远不会再次变为 false。

也许是这样的:

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

代替 if 并删除var stop = false;上面的行。

于 2013-10-16T18:44:27.263 回答