为了账号安全,请及时绑定邮箱和手机立即绑定

边栏高度:offsetHeight的高度为空,取不到值是为什么?

var $ = function(id){

return document.getElementById(id);

}


var addEvent = function(obj,event,fn){

    if(obj.addEventListener){

    obj.addEventListener(event,fn,false);

    }else if(obj.attachEvent){

    obj.attachEvent('on'+event,fn);

    }

}

var domSider = $('J_BdSide');

var scrollEvent = function(){

var sideHeight = domSider.offsetHeight;

var screenHeight = document.documentElement.clientHeight||document.body.clientHeight;

var scrollHeight = document.documentElement.scrollTop||document.body.scrollTop;

if(scrollHeight+screenHeight>sideHeight){

domSider.style.cssText = 'position:fixed;right:0px;top:'+(-(sideHeight-screenHeight))+'px';

}else{

domSider.style.position='static';

}

}

addEvent(window,'scroll',function(){

scrollEvent();

});

addEvent(window,'resize',function(){

scrollEvent();

});


正在回答

举报

0/150
提交
取消

边栏高度:offsetHeight的高度为空,取不到值是为什么?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信