js控制元素显示在屏幕固定位置及监听屏幕高度变化的方法
本文实例讲述了js控制元素显示在屏幕固定位置及监听屏幕高度变化的方法。分享给大家供大家参考。具体如下:
//控制logo的显示位置Begin
window.addEventListener("resize",function(){
//得到屏幕尺寸(内部/外部宽度,内部/外部高度)
changeLogoPosition();
},false);
changeLogoPosition();
functionchangeLogoPosition(){
varcontentHeight=$("#main_content_div").css("height");
varlogoHeight=$("#third_party_logo").css("height");
contentHeight=parseInt(contentHeight.replace('px',''));
logoHeight=parseInt(logoHeight.replace('px',''));
//alert('屏幕高度:'+document.body.scrollHeight+'内容高度:'+contentHeight+'logo高度:'+logoHeight);
if(document.body.scrollHeight-contentHeight>logoHeight){
document.getElementById('third_party_logo').style.position='absolute';
}else{
document.getElementById('third_party_logo').style.position='';
}
}
//控制logo的显示位置End
希望本文所述对大家的javascript程序设计有所帮助。