转载于http://www.cnblogs.com/piuba/archive/2013/01/06/2847295.html
http://blog.sina.com.cn/s/blog_74f1a3280102uyxp.html
$(document)与$(window)的区别
$(window)和$(document)获取到的对象不同。
1、Window 对象表示一个浏览器窗口或一个框架。在客户端 JavaScript 中,Window 对象是全局对象,所有的表达式都在当前的环境中计算.
2、Document 对象是 Window 对象的一部分,每个载入浏览器的 HTML 文档都会成为 Document 对象.
$(window).height()和$(document).height()
$(window).height()代表了当前可见区域的大小,而$(document).height()则代表了整个文档的高度,可视具体情况使用.
注意当浏览器窗口大小改变时(如最大化或拉大窗口后) $(window).height() 随之改变,但是$(document).height()是不变的。
$(document).scrollTop() 获取垂直滚动的距离 即当前滚动的地方的窗口顶端到整个页面顶端的距离
$(document).scrollLeft() 这是获取水平滚动条的距离
只需要获取到$(document).scrollTop()==0的时候 就是顶端了
只要$(document).scrollTop()>=$(document).height()-$(window).height() 就可以知道已经滚动到底端了
$(document).height() //是获取整个页面的高度
$(window).height()
//是获取当前 也就是你浏览器所能看到的页面的那部分的高度.这个大小在你缩放浏览器窗口大小时会改变,与document是不一样的
动手实验
<script>
$(function(){
$(document).scroll(function(){
$("#lb").html('$(document).scrollTop() '+$(document).scrollTop() +'<br>'+
'$(document).height() '+$(document).height() +'<br>'+
'$(window).height() ' +$(window).height());
})
});
</script>
<div style="background-color: orange;height:2000px"></div>
<span id="lb" style="top:0px;left:0px;position:fixed;font-size:30px"></span><!--一个固定的span标记 滚动时方便查看-->
document与window
请移步
http://blog.youkuaiyun.com/linghu_java/article/details/7300028
具体方法
一、Window对象
————————————————– ——————-
对象属性
window //窗户自身
window.self //引用本窗户window=window.self
window.name //为窗户命名
window.defaultStatus //设定窗户状态栏信息
window.location //URL地址,配备布置这个属性可以打开新的页面
————————————————– ——————-
对象方法
window.alert(“text”) //提示信息会话框
window.confirm(“text”) //确认会话框
window.prompt(“text”) //要求键盘输入会话框
window.setIntervel(“action”,time) //每一隔指定的时间(毫秒)就执行一次操作
window.clearInterval() //清除时间配备布置作用就是终止轮回
window.setTimeout(action,time) //隔了指定的时间(毫秒)执行一次操作
window.open() //打开新的窗户
window.close() //关闭窗户
————————————————– ——————-
成员对象
window.event
window.document //见document对象详解
window.history
window.screen
window.navigator
window.external
————————————————– ——————-
window.history对象
window.history.length //浏览过的页面数
history.back() //撤退退却
history.forward() //进步
history.go(i) //前进或头退到历史记录的第i个页面
//i>0进步,i<0撤退退却
————————————————– ——————-
window.screen对象
window.screen.height //屏幕高度
window.screen.colorDepth //屏幕色深
window.screen.availWidth //可用宽度
window.screen.availHeight //可用高度(除去任务栏的高度)
————————————————– ——————-
window.external对象
window.external.AddFavorite(“地址”,”标题” ) //把网站新增到保藏夹
————————————————– ——————-
window.navigator对象
window.navigator.appCodeName //浏览器代码名
window.navigator.appName //浏览器步伐名
window.navigator.appMinorVersion //浏览器补钉版本
window.navigator.cpuClass //cpu类型 x86
window.navigator.platform //操作体系类型 win32
window.navigator.plugins
window.navigator.opsProfile
window.navigator.userProfile
window.navigator.systemLanguage //客户体系语言 zh-cn简体中文
window.navigator.userLanguage //用户语言,同上
window.navigator.appVersion //浏览器版本(包括 体系版本)
window.navigator.userAgent
window.navigator.onLine //用户否在线
window.navigator.cookieEnabled //浏览器是否撑持cookie
window.navigator.mimeTypes
==================================================
二、document对象
对象属性:
document.title
document.bgColor
document.fgColor
document.linkColor
document.alinkColor
document.vlinkColor
document.URL
document.fileCreatedDate
document.fileModifiedDate
document.fileSize
document.cookie
document.charset
—————————-
常用对象方法
document.write()
document_createElement_x_x_x(Tag)
document.getElementByIdx_x_x_x(ID)
document.getElementsByName(Name)
document.body.a(oTag)
body-主体子对象
document.body
document.body.bgColor
document.body.link
document.body.alink
document.body.vlink
document.body.text
document.body.innerText
document.body.innerHTML
document.body.topMargin
document.body.leftMargin
document.body.rightMargin
document.body.bottomMargin
document.body.background
document.body.a(oTag) //动态生成一个HTML对象
常用对象事件
document.body.οnclick=”func()”
document.body.οnmοuseοver=”func()”
document.body.οnmοuseοut=”func()”
location-位置子对象
document.location.hash
document.location.host
document.location.hostname
document.location.href
document.location.pathname
document.location.port
document.location.protocol
document.location.search
常用对象事件
documeny.location.reload()
document.location.reload(URL)
document.location.assign(URL)
document.location.replace(URL)
========================================================================
selection-选区子对象
document.selection
========================================================================
images集合(页面中的图象):
—————————-
a)通过集合引用
document.images img标签
document.images.length img标签的个数
document.images[0] img标签
document.images[i] 标签
—————————-
b)通过nane属性直接引用
document.images.oImage
—————————-
c)引用图片的src属性
document.images.oImage.src
—————————-
d)创建一个图象
var oImage
oImage = new Image()
document.images.oImage.src=”1.jpg”
同时在页面上建立一个img标签与之对应就可以显示