jQuery&CSS 顶部和底部固定浮动工具栏 兼容IE6
http://www.cnblogs.com/lhj588/archive/2013/04/02/2994639.html
————————————————————————————————————————————————————————————
现在常常能看到一些网站(如:新浪微博和花瓣)导航条或工具栏固定在网页的顶部或其他地方。这样的布局方式,能便于用户点击和“曝光率”,不用每次都要把网页拖动到某个特定位置才能点击或看到。
其实这样的布局方式很早就有,只是没有那么个契机推广开吧。做起来也不复杂,只要设置一个小小的属性“position:fixed”便能完成,最关键的无不呼在于要兼容IE6而已。
首先我们来看HTML代码,是不是超简单?这里提供的只是一个简单的框架,实际应用的时候,只要把想要的元素添加东西就在这区域内加就行。
HTML CODE:
<div id="header">Default header. No absolute and fixed.</div><div id="topToolbar">Fixed at the top of the Toolbar.</div><div id="content"> <p>此处省略1000字...</p></div><div id="bottomToolbar">Fixed at the bottom of the Toolbar. By Bluesdream.com</div> |
CSS CODE:
<style type="text/css">/* 全局CSS*/*{margin:0px; padding:0px;}a{ text-decoration:none; outline:none;}a:hover{text-decoration:underline;}/* 实例CSS */html{ _background:url(about:blank);} /*阻止闪动 in IE6 , 把空文件换成about:blank , 减少请求*/body{ font-size:12px; font-family:Arial,Tahoma,sans-serif; color:#EEEEEE; text-align:center; background:#E2E2E2;}#topToolbar{ _display:none; width:100%; height:40px; line-height:40px; background:#101010; border-bottom:2px solid #409F89; position:fixed; top:-40px; left:0; _position:absolute; _top:0;}#bottomToolbar{ width:100%; height:40px; line-height:40px; background:#101010; border-top:2px solid #409F89; position:fixed; bottom:0; left:0; _position:absolute; _top:expression(documentElement.scrollTop+documentElement.clientHeight-this.offsetHeight); /* document.body.scrollTop 网页滚动的距离 document.body.clientHeight 网页可见区域高 this.offsetHeight 当前元素的高度 */}#bottomToolbar a{ color:#FFF;}#header{ width:100%; height:80px; line-height:80px; background:#101010; border-top:2px solid #409F89;}#content{ width:880px; height:1390px; line-height:18px; text-align:left; margin:40px auto 80px auto; padding:30px 50px; background:#FFF url(images/scaleplate.png) no-repeat; border:1px solid #CCC;}</style> |
JAVASCRIPT CODE:
<script type="text/javascript">$(function(){ $(window).scroll(function() { var topToolbar = $("#topToolbar"); var headerH = $("#header").outerHeight(); var scrollTop = $(document).scrollTop(); //IE6 Expression方法和jquery animate方法同事使用会有问题,所以加个判断,简化下IE6下的显示方式. if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) { if( scrollTop >= headerH ){ topToolbar.show(); }else if( scrollTop < headerH ){ topToolbar.hide(); } }else{ if( scrollTop >= headerH ){ topToolbar.animate({ 'top':0 }); }else if( scrollTop < headerH ){ topToolbar.animate({ 'top':-40 }); } }; });});</script> |
如果要像新浪微博那样,始终浮动固定在顶部,那JS部分就可以无视了,有没有都无所谓,直接改CSS就行。
#topToolbar{ width:100%; height:40px; line-height:40px; background:#101010; border-bottom:2px solid #409F89; position:fixed; top:0; left:0; _position:absolute; _top:expression(documentElement.scrollTop);}jQuery&CSS 顶部和底部固定浮动工具栏 兼容IE6的更多相关文章
- jquery返回顶部和底部插件和解决ie6下fixed插件
(function($){ //返回顶部和底部插件 $.fn.extend({ goTopBootom:function (options){ //默认参数 var defaults = { &quo ...
- jquery垂直滚动插件一个参数用于设置速度,兼容ie6
利用外层的块级元素负外边距来滚动 1.使用 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://ww ...
- jQuery 顶部导航尾随滚动,固定浮动在顶部
jQuery 顶部导航尾随滚动.固定浮动在顶部 演示 XML/HTML Code <section> <article class="left"> < ...
- html中header,footer分别固定在顶部和底部
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>page01</title> 5 <styl ...
- div footer标签css实现位于页面底部固定
Web页面的“footer”部分随着飘上来,处在页面的半腰中间,给视觉效果带来极大的影响,让你的页面看上去很不好看,特别是现在宽屏越来越多,这种现象更是常见,本文将介绍两种解决方案,需要了解的朋友可以 ...
- 页面元素固定在页面底部的纯css代码(兼容IE6)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 微信小程序之顶部固定和底部固定
顶部固定 <view style="position:fixed;top:0;"> ...... </view> 底部固定 <view style=& ...
- bootstrap让footer固定在顶部和底部
一.原理 使用fixed进行固定定位,相对于浏览器窗口进行定位,然后再设置其z-index的值即可. 二.Bootstrap中使用的类 1.顶部固定:navbar-fixed-top 2.底部固定:n ...
- [jquery]判断页面滚动到顶部和底部(适用于手机web加载)
//判断页面滚动到顶部和底部 $(window).scroll(function(){ var doc_height = $(document).height(); var scroll_top = ...
随机推荐
- java方法的继承,覆盖与重载
java中的继承使用extends关键字,在子类继承了父类之后将会获得父类的全部属性与方法(父类的构造器除外).如果在定义java类时没有显示定义她的父类,那么这个类默认将扩展java.lang.Ob ...
- android sqlite3:数据库操作
1. 修改表名: alter table notification rename to notification_test 2. 修改数据库名称: 3. 复制一个表的数据到另外一个表中(表的字段一致) ...
- [svc]arpping链路层检测
arping命令,测试链路层是否同 参考 yum install iputils -y arping - send ARP REQUEST to a neighbour host -b:用于发送以太网 ...
- sql索引唯一
alter table et_tb_1111 add constraint tbunique unique (itemid) alter table 表名 add constraint 约束名 uni ...
- transfer learning
https://github.com/jindongwang/transferlearning ftp://ftp.cs.wisc.edu/machine-learning/shavlik-group ...
- oracle sql合计结果信息使用分组的小问题
--月统计 Select SUBSTR(t.BalanceDate,1,6) as Mon, t.RechargeType , SUM(t.SumNum) as SumNum , SUM(t.SumF ...
- LeetCode: Path Sum 解题报告
Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that addi ...
- Python3高级用法综合举例
[本文出自天外归云的博客园] 举例 下面代码围绕一个Student类综合举例说明装饰器.生成器.动态获取/添加类成员.列表推导式.reduce函数.lambda表达式的实际应用: from funct ...
- 移动web开发(二)——viewport
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scal ...
- java中volatile关键字的理解
一.基本概念 Java 内存模型中的可见性.原子性和有序性.可见性: 可见性是一种复杂的属性,因为可见性中的错误总是会违背我们的直觉.通常,我们无法确保执行读操作的线程能适时地看到其他线程写入的值,有 ...