IE6不支持fixed
2016-05-27 16:15
204 查看
#goto-top { display:none; position:fixed; width:38px; height:36px; background:url(../images/goto-top.png) no-repeat 0 0; bottom:40px; right:40px; -webkit-transition:all 0.2s; -moz-transition:all 0.2s; -o-transition:all 0.2s; transition:all 0.2s; z-index:9999; } /*ie6*/ * html body {background-image:url(about:blank);background-attachment:fixed} /*解决IE6闪动*/ * html #goto-top{ _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0))); _margin-bottom: 40px; /*定位底部*/ }
注释:right 跟 left 属性可以用绝对定位的办法解决,而 top 跟 bottom 就需要用上面的表达式来实现。其中在
_position:absolute;中的
_符号只有 IE6 才能识别,目的是为了区分其他浏览器。
使元素固定在浏览器的顶部
#top{ _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop));}
使元素固定在浏览器的底部
#top{ _position:absolute; _bottom:auto; _top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}
这两段代码只能实现在最底部跟最顶部,你可以使用
_margin-top:10px;或者
_margin-bottom:10px;修改其中的数值控制元素的位置。
position:fixed; 闪动问题
现在,问题还没有完全解决。在用了上面的办法后,你会发现:被固定定位的元素在滚动滚动条的时候会闪动。解决闪动问题的办法是在 CSS 文件中加入:*html{ background-image:url(about:blank); background-attachment:fixed;}
其中
*是给 IE6 识别的。
相关文章推荐
- 读jQuery源码释疑笔记2
- 餐饮管理系统之员工管理
- 隐藏/修饰页面的滚动条
- 集成shareSDK3.3.0所遇到的问题
- JuheNews系列之二 · ToolBar+AppBarLayout+CoordinatorLayout+CollapsingToolbarLayout
- Android 学习路线总结
- 自行编写strcpy()函数
- 解决Grails端口号冲突问题
- Java中vector的使用详解
- 安卓Transition学习(一)
- 二叉树
- 解决AndroidStudio从网络引入三方jar包,项目中无法找到类问题
- 【论文笔记】Mutual-Structure for Joint Filtering
- JAVA 程序设置运行内存
- PAT 1013. Battle Over Cities (25)(并查集||DFS)
- Caffe源码阅读(2) 卷积层
- const、volatile、mutable的用法
- Excel
- CSS边框
- html前端代码