Javascript 持久标题会导致网站高度崩溃

Javascript 持久标题会导致网站高度崩溃,javascript,jquery,html,css,Javascript,Jquery,Html,Css,这是我的代码: $(函数(){ 变量$select=$('#select'); 变量$window=$(window); var isFixed=假; var init=$select.length?$select.offset()。顶部:0; $window.scroll(函数(){ var currentScrollTop=$window.scrollTop(); if(currentScrollTop>init&&isFixed==false){ isFixed=true; $sele

这是我的代码:

$(函数(){
变量$select=$('#select');
变量$window=$(window);
var isFixed=假;
var init=$select.length?$select.offset()。顶部:0;
$window.scroll(函数(){
var currentScrollTop=$window.scrollTop();
if(currentScrollTop>init&&isFixed==false){
isFixed=true;
$select.css({
排名:0,
位置:'固定'
});

}否则,如果(currentScrollTop当位置设置为固定时,在主体顶部添加填充物以容纳它。同样,当元素未固定时,移除填充物:

if (currentScrollTop > init && isFixed === false) {
    isFixed = true;
    $select.css({
        top: 0,
        position: 'fixed'
    });
    $('body').css('padding-top', $select.height());
} 
else if (currentScrollTop <= init && isFixed === true) {
    isFixed = false;
    $select.css('position', 'relative');
    $('body').css('padding-top', 0);
}
if(currentScrollTop>init&&isFixed==false){
isFixed=true;
$select.css({
排名:0,
位置:'固定'
});
$('body').css('padding-top',$select.height());
} 

否则,如果(currentScrollTop),您能否为蓝色div指定一个height属性,以便不显示缺少的黄色div?
if (currentScrollTop > init && isFixed === false) {
    isFixed = true;
    $select.css({
        top: 0,
        position: 'fixed'
    });
    $('body').css('padding-top', $select.height());
} 
else if (currentScrollTop <= init && isFixed === true) {
    isFixed = false;
    $select.css('position', 'relative');
    $('body').css('padding-top', 0);
}