$(document).height()与$(window).height()
来源:互联网 发布:中国国民收入数据库 编辑:程序博客网 时间:2024/04/30 14:02
jQuery(window).height()代表了当前可见区域的大小,而jQuery(document).height()则代表了整个文档的高度,可视具体情况使用.注意当浏览器窗口大小改变时(如最大化或拉大窗口后) jQuery(window).height() 随之改变,但是jQuery(document).height()是不变的。
$(document).scrollTop() 获取垂直滚动的距离 即当前滚动的地方的窗口顶端到整个页面顶端的距离$(document).scrollLeft() 这是获取水平滚动条的距离要获取顶端 只需要获取到scrollTop()==0的时候 就是顶端了要获取底端 只要获取scrollTop()>=$(document).height()-$(window).height() 就可以知道已经滚动到底端了
jQuery判断div随滚动条滚动到一定位置后停止
<script type="text/javascript">
var rollSet = $('#widget');
var offset = rollSet.offset();
var fwidth = $("#footer").height();
$(window).scroll(function() {
var scrollTop = $(window).scrollTop();
var scrollBtm = $(document).height() - $(window).scrollTop() - $("#widget").height();
if (offset.top < scrollTop) {
if (scrollBtm > fwidth) {
rollSet.removeClass('absolute').addClass('fixed')
} else {
rollSet.removeClass('fixed').addClass('absolute')
}
} else {
rollSet.removeClass('fixed')
}
})
</script>
方法说明:
由页面总高度减去已滚动的高度再减去ID为widget的层的高度即等于该层底部距离底部的高度;
当距离底部的高度小于或等于特定位置距离底部的高度时,去掉样式fixed,然后给该层添加绝对定位!
CSS中要给父父层添加position:relative;
0 0
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- $(document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- $(window).height()与$(document).height()
- $(document).height()与$(window).height()
- (document).height()与$(window).height()
- (document).height()与$(window).height()
- $(document).height()与$(window).height()的区别
- $(document).height()与$(window).height()区别
- $(window).height()和$(document).height()
- (document).height()与$(window).height()和顶部底部数据获取
- Spring MVC 框架搭建及详解
- eclipse+axis2配置
- U-boot 2014 启动流程详细分析
- Oracle笔记之序列
- WinForm 自定义窗体的拖动方法
- $(document).height()与$(window).height()
- Anonymous Classes
- 快速排序的简单实现
- 【HDU 3270】Cow Sorting
- 网络访问流程
- Linux C++ 使用condition实现阻塞队列
- 奇怪的分式
- 东软学习,sql工具类
- 合同如火如荼有态度与合同任何人