获取页面window/document的值
2012-04-22 18:41
225 查看
javascript
jQuery:
//页面位置及窗口大小 function GetPageSize() { var scrW, scrH; if(window.innerHeight && window.scrollMaxY) { // Mozilla scrW = window.innerWidth + window.scrollMaxX; scrH = window.innerHeight + window.scrollMaxY; } else if(document.body.scrollHeight > document.body.offsetHeight) { // all but IE Mac scrW = document.body.scrollWidth; scrH = document.body.scrollHeight; } else if(document.body) { // IE Mac scrW = document.body.offsetWidth; scrH = document.body.offsetHeight; } var winW, winH; if(window.innerHeight) { // all except IE winW = window.innerWidth; winH = window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // IE 6 Strict Mode winW = document.documentElement.clientWidth; winH = document.documentElement.clientHeight; } else if (document.body) { // other winW = document.body.clientWidth; winH = document.body.clientHeight; } // for small pages with total size less then the viewport var pageW = (scrW<winW) ? winW : scrW; var pageH = (scrH<winH) ? winH : scrH; return {PageW:pageW, PageH:pageH, WinW:winW, WinH:winH}; }; //滚动条位置 function GetPageScroll() { var x, y; if(window.pageYOffset) { // all except IE y = window.pageYOffset; x = window.pageXOffset; } else if(document.documentElement && document.documentElement.scrollTop) { // IE 6 Strict y = document.documentElement.scrollTop; x = document.documentElement.scrollLeft; } else if(document.body) { // all other IE y = document.body.scrollTop; x = document.body.scrollLeft; } return {X:x, Y:y}; }
jQuery:
获取浏览器显示区域的高度 : $(window).height(); 获取浏览器显示区域的宽度 :$(window).width(); 获取页面的文档高度 :$(document).height(); 获取页面的文档宽度 :$(document).width(); 获取滚动条到顶部的垂直高度 :$(document).scrollTop(); 获取滚动条到左边的垂直宽度 :$(document).scrollLeft(); 计算元素位置和偏移量 offset方法是一个很有用的方法,它返回包装集中第一个元素的偏移信息。默认情况下是相对body的偏移信息。结果包含 top和left两个属性。 offset(options, results) options.relativeTo 指定相对计 算偏移位置的祖先元素。这个元素应该是relative或absolute定位。省略则相对body。 options.scroll 是否把 滚动条计算在内,默认TRUE options.padding 是否把padding计算在内,默认false options.margin 是否把margin计算在内,默认true options.border 是否把边框计算在内,默认true
$(function() { $("#return_top").click(function() { var scro = $(document).scrollTop(); alert(scro); document.body.scrollTop = 0; document.documentElement.scrollTop = 0; }); });
$(window).scrollTop(0);
相关文章推荐
- html页面的三个width: document, window, screen
- jquery与javascript中的两个页面加载事件 window.onload 与 $(document).ready(function(){})区别
- document.body、document.documentElement和window获取视窗大小的区别
- 关于document.body、document.documentElement和window获取视窗大小的区别
- jQuery mobile在页面加载时添加加载中效果 document.ready 和window.onload执行顺序比较
- CHtmlView获取页面的Document注意事项
- js获取宽度 ,各种高度宽度document.body.clientWidth , document.body.clientHeight,window.screen.width 等等
- 网页页面中的区域控制 (document.body与window.screen)
- javascript window获取iframe、iframe获取window、document
- JS控制静态页面之间传递参数获取参数并应用(window.location)
- JS获取上一访问页面URL地址document.referrer实践
- 2018-1-18解决js调父页面标签操作window.parent.document.getElementById().innerHTML
- JS中页面加载事件window.onload、onload()、document.onclick
- iframe子窗体和父窗体互相调用,通过document.getElementById("name_iframe").contentWindow获取iframe的window对象,支持多浏览器!
- iframe父子页面操作-比较好用的两个方法-window.parent/oframe.contentWindow.document
- JS控制静态页面之间传递参数获取参数并应用(window.location)
- document.body、document.documentElement和window获取视窗大小的区别
- jQuery获取window、document、dom元素的高度和宽度函数分析
- WebBrowser之获取跳转页面的Document接口源码
- 用window.open()方法打开的页面 获取到父页面 属性的值