获取屏幕的高和宽度

js获取
/********************
 * 取窗口滚动条滚动高度  
 ******************/
function getScrollTop()
{
  var scrollTop=0;
  if(document.documentElement&&document.documentElement.scrollTop)
  {
  scrollTop=document.documentElement.scrollTop;
  }
  else if(document.body)
  {
  scrollTop=document.body.scrollTop;
  }
  return scrollTop;
}


/********************
 * 取窗口可视范围的高度  
 *******************/
function getClientHeight()
{
  var clientHeight=0;
  if(document.body.clientHeight&&document.documentElement.clientHeight)
  {
  var clientHeight = (document.body.clientHeight
  }
  else
  {
  var clientHeight = (document.body.clientHeight>document.documentElement.clientHeight)?document.body.clientHeight:document.documentElement.clientHeight;   
  }
  return clientHeight;
}

/********************
 * 取文档内容实际高度  
 *******************/
function getScrollHeight()
{
  return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);

}

-------------------------------------------------------------------------------------------------------------------------------

var winWidth=0;
var winHeight=0;
//获取窗口宽度
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){
winWidth = document.documentElement.clientWidth;
winHeight = document.documentElement.clientHeight;
}

$("#div1).css({"height":parseInt(winHeight),"width":parseInt(winWidth)});


------------------------------------------------------------------------------------------------------------------

console.log($(document).width() + " " + $(document).height());
console.log($(window).width() + " " + $(window).height());

你可能感兴趣的:(js)