获取页面高度窗口高度滚动条高度等参数值getPageSize,getPageScroll

2016-02-19 11:59 63 1 收藏

最近很多朋友喜欢上设计,但是大家却不知道如何去做,别担心有图老师给你解答,史上最全最棒的详细解说让你一看就懂。

【 tulaoshi.com - Web开发 】

代码如下:

function getPageScroll(){
  var yScroll;
  if (self.pageYOffset) {
    yScroll = self.pageYOffset;
  } else if (document.documentElement && document.documentElement.scrollTop){   // Explorer 6 Strict
    yScroll = document.documentElement.scrollTop;
  } else if (document.body) {// all other Explorers
    yScroll = document.body.scrollTop;
  }

  arrayPageScroll = new Array('',yScroll) 
  return arrayPageScroll;
}

function getPageSize(){  
  var xScroll, yScroll;  
  if (window.innerHeight && window.scrollMaxY) {  
    xScroll = document.body.scrollWidth;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight  document.body.offsetHeight){ // all but Explorer Mac
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
    xScroll = document.body.offsetWidth;
    yScroll = document.body.offsetHeight;
  }

  var windowWidth, windowHeight;
  if (self.innerHeight) {  // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }  

  // for small pages with total height less then height of the viewport
  if(yScroll  windowHeight){
    pageHeight = windowHeight;
  } else { 
    pageHeight = yScroll;
  }

  if(xScroll  windowWidth){  
    pageWidth = windowWidth;
  } else {
    pageWidth = xScroll;
  }

  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
  return arrayPageSize;
}

来源:https://www.tulaoshi.com/n/20160219/1599393.html

延伸阅读
家具高度有学问,装修中家具高度的选择 经常有朋友问居室装修中各种家具的高度。的确如此,到了一个环境如果各个家具高度对您来说都是得心应手的,那会生活的非常舒服,如果家具高度不正确,那么生活起来就十分的别扭,哪怕只差1cm,也会使我们束手束脚。家庭中的日用品和常用器具,宜放在容易靠近的地方或置于容易使用的位置。下...
标签: 饮食禁忌
蚕豆病在我周围越来越普遍,我很担心周围的人用药不对而加重病情。我知道蚕豆病患者会出现溶血症状,这是非常严重的,所以我想知道蚕豆病的用药禁忌是什么,下面就让图老师小编带着大家一起来看看吧。 我很怕一个不小心会使得病症更加严重,一旦溶血,来势凶猛。我也了解到身边很多人都不太了解蚕豆病,如果用错药,后果将不堪设想,...
标签: 生活常识
床靠背高度多高合适   床是一个可以令人放松的地方。有人喜欢在睡前看看书,听听歌,床靠背却是我们值得依靠的肩膀。家居风水学上,非常忌讳床无靠背。床无靠背,顾名思义就是床的背后没有靠山,陷入孤身的困境,睡在上面人精神容易恍惚,缺乏安全感。至于床靠背高度和床靠背尺寸是多少呢,下面就让图老师小编为大家解答一下吧。 ...
标签: 孕期
“十月怀胎”与“四十周”    宝宝从受精的那一天开始,到母体分娩出,一般应为266天。而你平日通常听到的十月怀胎、怀孕40周以及怀孕280天是怎么回事呢?  tulaoshi;  原来整个怀孕期是从末次月经的第一天开始计算的,也就是要早14天。即整个孕期的280天、40周。    之所以将280天、...
标签: Web开发
1.背景图填充 这是使用最广泛的一种做法,无hacks,推荐使用: !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"html xmlns="http://www.w3.org/1999/xhtml"headmeta http-equiv="Content-Type" content="text/html; charset=...

经验教程

255

收藏

30
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部