在Safari中打破'Sticky'导航栏

时间:2012-07-25 16:14:28

标签: jquery navigation sticky

我正在尝试使用此代码制作“粘性”导航栏。当我在Safari中查看它时它被打破了(当我向下滚动大约10px时,我的浏览器跳转到导航栏,大约是350px)

$(document).ready(function() {

    //Calculate the height of <header>
    //Use outerHeight() instead of height() if have padding
    var aboveHeight = $('header').outerHeight();

//when scroll
    $(window).scroll(function(){

        //if scrolled down more than the header’s height
            if ($(window).scrollTop() > aboveHeight){

        // if yes, add “fixed” class to the <nav>
        // add padding top to the #content
            (value is same as the height of the nav)
            $('nav').addClass('fixed').css('top','0').next()
            .css('padding-top','60px');

            } else {

        // when scroll up or less than aboveHeight,
            remove the “fixed” class, and the padding-top
            $('nav').removeClass('fixed').next()
            .css('padding-top','0');
            }
    });
});

0 个答案:

没有答案