jQuery里面的$(window).height()和$(document).height()的区别
2015-06-22 19:46
597 查看
我们要知道,$(window).height(),获取的是窗口的可视区域的高度,而$(document).height();获取的是文档的高度。
所以当你改变窗口的时候,$(window).height()会随着窗口的改变而改变,但$(document).height()是不变的。
很多时候,我们要使元素居中,此时我们可以写一个插件命名为jQuery.center.js,jQuery.fn.center = function(){
this.css({
"position":"absolute",
"top":(($(window).height()-this.height())/2+$(window).scrollTop())+"px",
"left":(($(window).width()-this.width())/2+$(window).scrollLeft())+"px"
});
return this;
}
此时可以在文件中引入jQuery.center.js插件,然后对某个对象调用该方法,例如:$("div").center();
所以当你改变窗口的时候,$(window).height()会随着窗口的改变而改变,但$(document).height()是不变的。
很多时候,我们要使元素居中,此时我们可以写一个插件命名为jQuery.center.js,jQuery.fn.center = function(){
this.css({
"position":"absolute",
"top":(($(window).height()-this.height())/2+$(window).scrollTop())+"px",
"left":(($(window).width()-this.width())/2+$(window).scrollLeft())+"px"
});
return this;
}
此时可以在文件中引入jQuery.center.js插件,然后对某个对象调用该方法,例如:$("div").center();
相关文章推荐
- jQueryCDN
- Jquery1.6版本后attr的变化,灰常委屈
- jquery easyui常见问题:
- jquery多选下拉框左右复制
- jquery-ajax
- 跨域之-jquery操作
- jquery根据name属性查找元素
- 最最基层的ajax交互代码jquery+java之间的json跨域传递以及java的json代码返回
- 使用jquery+ajax+php实现搜索框的功能
- JQuery处理checkbox的checked属性正确用法
- jquery 使用$.ajax post方法提交数据
- 使用jQeury控制form动态发送请求
- 浅谈jquery中delegate()与live()
- jQuery初学者必看
- jquery 中ajax执行的优先级
- jquery中ready()函数执行的时机和window的load事件比较
- jquery easyui读取json文件乱码
- jquery中toggle函数交替使用问题
- 深入理解jQuery插件开发---转载
- jquery ajax 显示服务器时钟