1、screen
- window.screen 对象包含有关用户屏幕的信息
- screen.availWidth 屏幕宽度
- screen.availHeight 屏幕高度
2、history
- forward() 方法可加载历史列表中的下一个页面
- back() 方法可加载历史列表中的前一个页面(如果存在)
- go() 方法可加载历史列表中的某个页面 参数为正前进,参数为负后退
3、location
- location.href 返回当前页面的地址
- location.pathname 返回 路径名
- location.reload() 刷新本页面
4、navigator
5、window对象常用方法
prompt
显示可提示用户输入的对话框
alert
显示带有一个提示信息和一个确定按钮的警示框
confirm
显示一个带有提示信息、确定和取消按钮的对话框
close
关闭浏览器窗口
open
打开一个新的浏览器窗口,加载给定 URL 所指定的文档
setTimeout
在指定的毫秒数后调用函数或计算表达式
setInterval
按照指定的周期(以毫秒计)来调用函数或表达式
window.open(URL,name,features)打开一个新的浏览器窗口
window.close()关闭浏览器窗口
6、window对象常用事件
onload | 一个页面或一幅图像完成加载 在对象已加载时触发 |
onresize | 随着窗口或框架大小的改变而改变 window.οnresize=function(){} |
onscroll | 滚动条滚动事件 |
当滚动条滚动的时候,获取滚动条数据
document.documentElement.scrollTop; 获取顶部
document.documentElement.scrollLeft; 获取左部
document.body.scrollTop;
document.body.scrollLeft;
兼容写法:
var wtop = document.documentElement.scrollTop || document.body.scrollTop;
利用scroll设置回到顶部和吸顶效果 var top = document.getElementById("top"); var timer = null, a; top.onclick = function () { clearInterval(timer); timer = setInterval(function () { document.documentElement.scrollTop -= 20; a = document.documentElement.scrollTop; if (a == 0) { clearInterval(timer); } }, 10) } var two = document.getElementById("two"); window.onscroll = function () { var b = document.documentElement.scrollTop; if (b > 200) { two.style.position = "fixed"; two.style.top="0"; two.style.left="0"; }else{ two.style.position=""; } }