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 = ...
随机推荐
- redis transactions(事务)
MULTI MULTI:标记一个事务块的开始. 事务块内的多条命令会按照先后顺序被放进一个队列当中,最后由 EXEC 命令原子性(atomic)地执行. 可用版本:>= 1.2.0 时间复杂度: ...
- 微信小程序如何获取屏幕宽度
微信小程序如何获取屏幕宽度 方法1: imageLoad: function () { this.setData({ imageWidth: wx.getSystemInfoSync().window ...
- Linux系统和工具集
Linux系统和工具集 阿里源 http://mirrors.aliyun.com/ http://centos.ustc.edu.cn/ 第三方包管理器 不同的发行版使用不同的软件包管理器,Cent ...
- 绕过chrome的弹窗拦截机制
在chrome的安全机制里面,非用户触发的window.open方法,是会被拦截的.举个例子: var btn = $('#btn'); btn.click(function () { //不会被拦截 ...
- 360wifi: 手机锁屏360wifi掉线的解决方法
如遇到iphone锁屏断网的情况,按照以下操作步骤可以解决一部分用户的问题 (该问题并不是360WifFi问题,与苹果机制有关)如有安卓手机掉线,请确保手机连接其他Wifi并不会掉线,然后尝试粉色字体 ...
- Gartner 2018新技术成熟度曲线
https://blog.csdn.net/BtB5e6Nsu1g511Eg5XEg/article/details/82047719 近日,Gartner发布了2018年新技术成熟度曲线,首次将生物 ...
- 每日英语:Are Smartphones Turning Us Into Bad Samaritans?
In late September, on a crowded commuter train in San Francisco, a man shot and killed 20-year-old s ...
- Linux 关于Transparent Hugepages的介绍【转】
透明大页介绍 Transparent Huge Pages的一些官方介绍资料: Transparent Huge Pages (THP) are enabled by default in RHEL ...
- 使用 IDEA 开发工具(版本为 IntelliJ IDEA 14.1.4)打可执行jar包的操作步骤
声明:教程演示使用的开发工具的版本是 IntelliJ IDEA 14.1.4. 1.选择IDEA开发工具菜单栏 File --> Project Structure,弹出如下窗口,在左侧的列表 ...
- LOCAL_EXPORT_C_INCLUDES和LOCALC_INCLUDES 的差别
http://stackoverflow.com/questions/6595208/what-does-this-line-mean-local-export-c-includes LOCAL_EX ...