jQuery在第一次加载时给出了标题负面位置

时间:2013-08-15 12:34:37

标签: jquery css

我正在使用一些jQuery,当使用class =“bumper”到达div时,会使固定的标头停止。 当我在本地尝试这个时,我没有遇到任何问题。但是,现在,由于某种原因,标头设置为-220px(当我检查元素时由element.style表示)缓存时(如果你重新加载页面),这没有问题。 是什么导致了这个问题?

以下是该页面的链接: http://www.carlpapworth.com/development/utt.se/index.html

这是CSS:

header{
width: 100%;
height: 100px;
position: fixed;
top: 0;
background-image: url(../images/milkBG.png);
z-index: 3000;
padding: 5px 0 10px 0;
}

这是JS:

$(document).ready(function() {
//stop-header\\
    var windw = this;
    $.fn.followTo = function ( elem ) {
        var $this = this,
            $window = $(windw),
            $bumper = $(elem),
            bumperPos = $bumper.offset().top,
            thisHeight = $this.outerHeight(),
            setPosition = function(){
                if ($window.scrollTop() > (bumperPos - thisHeight)) {
                    $this.css({
                        position: 'absolute',
                        top: (bumperPos - thisHeight)
                    });
                } else {
                    $this.css({
                        position: 'fixed',
                        top: 0
                    });
                }
            };
        $window.resize(function()
        {
            bumperPos = pos.offset().top;
            thisHeight = $this.outerHeight();
            setPosition();
        });
        $window.scroll(setPosition);
        setPosition();
    };
    $('header').followTo('.bumper');
});

0 个答案:

没有答案