JS实现让页脚一直固定在页面底部
2016-11-18 00:00
489 查看
JS实现页脚在浏览器可视范围内始终置底。
如下图所示:
代码如下:
如下图所示:
代码如下:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JS实现让页脚一直固定在页面底部</title> <meta name="generator" content="editplus" /> <meta name="author" content="" /> <meta name="keywords" content="" /> <meta name="description" content="" /> <style type="text/css"> *{margin:0px;padding:0px;} body{font-size:12px;font-family:"微软雅黑";color:#ddd;background:#eee;} .header{width:100%;height:98px;background:#111;padding:1px 0px;color:#fff;font-size:24px;text-align:center;} .content{width:1500px;height:700px;background:#004f27;margin:0px auto;color:#fff;font-size:24px;text-align:center;} .footer{width:100%;height:50px;background:#111;color:#fff;font-size:24px;text-align:center;} </style> </head> <body> <div class="header">头部</div> <div class="content">内容区域</div> <div class="footer">底部</div> </body> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $(window).bind("load", function() { var footerHeight = 0; var footerTop = 0; positionFooter(); function positionFooter() { // 获取页脚的高度 footerHeight = $(".footer").height(); // 获取页脚的高度 /* scrollTop() 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离 */ footerTop = ($(window).scrollTop()+$(window).height()-footerHeight)+"px"; //如果页面内容高度小于屏幕高度,div#footer将绝对定位到屏幕底部,否则div#footer保留它的正常静态定位 if(($(document.body).height()+footerHeight) < $(window).height()) { $(".footer").css({ position: "absolute",left:"0" }).stop().css({top:footerTop}); } } $(window).scroll(positionFooter).resize(positionFooter); }); </script> </html>
相关文章推荐
- JS实现让页脚一直固定在页面底部
- 通过jQuery来实现页脚永远固定在页面底部的效果
- 如何将页脚固定在页面底部(多种方法实现)
- 通过jQuery来实现页脚永远固定在页面底部的效果
- 如何将页脚固定在页面底部(多种方法实现)
- 将页脚固定在页面的底部
- 如何将页脚固定在页面底部
- 页脚固定页面底部
- JS实现判断滚动条滚到页面底部并执行事件的方法
- 如何将页脚固定在页面底部
- js实现html页面滚动条向下拉到一定的程度时,某个div就固定在顶部,向上拉时返回原位置。
- 将页脚保持在页面的底部——Javascript+Css实现
- .如何将页脚固定在页面底部
- 纯css实现固定在页面底部的div层
- JS实现判断滚动条滚到页面底部并执行事件的方法
- 如何将页脚固定在页面底部
- 始终在页面底部的层js实现代码
- window.location.href妙用 标签里用js 利用这个简单的转换思路 实现 一直也无法实现的在 页面的html标签使
- 如何将页脚固定在页面底部
- div footer标签css实现位于页面底部固定