chorme浏览器div包含img标签页面总超出浏览器页面高度

<div style="display:block;position:absolute;left:0px;top:0px;" id="backgroundImg"><img src="img/zx-user-login/2.jpg" style="width:100%;height:100%;"  /></div>
js如下:
$(function(){
	    $(document).ready(function(){
		  alert($(window).width()+","+$(window).height());
		  $("#backgroundImg").css({
		    width:findDimensions().winWidth,
			height:findDimensions().winHeight
		  });
		});
	    $(window).on("resize",function(){
		  $("#backgroundImg").css({
		     width:findDimensions().winWidth,
			height:findDimensions().winHeight
		  });
		})
	  });
	  <!-- 获取浏览器频幕宽高参数 -->
	  function getWinScale(){
	    defaults = {winWidth:$(window).width(),winHeight:$(window).height()};
	    return defaults;
	  }
	  function findDimensions(){  //函数:获取尺寸
		//获取窗口宽度 
		if (window.innerWidth) 
			winWidth = window.innerWidth; 
		else if ((document.body) && (document.body.clientWidth)) 
			winWidth = document.body.clientWidth; 
		//获取窗口高度 
		if (window.innerHeight) 
			winHeight = window.innerHeight; 
		else if ((document.body) && (document.body.clientHeight)) 
			winHeight = document.body.clientHeight; 
		//通过深入Document内部对body进行检测,获取窗口大小 
		if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) { 
			winHeight = document.documentElement.clientHeight; 
			winWidth = document.documentElement.clientWidth; 
		} 
		defaults = {winWidth:winWidth,winHeight:winHeight};
		return defaults;
	  }

页面总是超出浏览器页面高度,

解决办法:

给img父容器div添加样式:font-size:0px;

你可能感兴趣的:(浏览器,window,function,document,标签)