浮动层固定兼容IE6 position:fixed的最佳解决方案
第一种:css方法
有时候当我们需要把一个元素固定在页面的某个部位,一般都是用css中的“position:fixed;”方法来解决,但是IE6不支持fixed,所以今天分享一个兼容IE6的页面底部固定层CSS代码。如下:
.bottom{bottom:0;position:fixed;height:23px;line-height:23px;width:100%;z-index:999;
_bottom:auto;_width:100%;_position:absolute;
//_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}
_top:expression(documentElement.scrollTop + documentElement.clientHeight-this.offsetHeight);
/* for IE6 ,执行JS语句,documentElement即html对象,clientHeight即可视窗口高度,
offsetHeight即浮动层高度(包括border边框厚度),scrollTop即滚动条滚动过的页面高度 */
需要注意的是:使用以上代码后在ie中你会发现被固定定位的元素在滚动滚动条的时候会闪动,下面给出解决方法:
//body{background:url(notfound)fixed;}
body{
background-image:url(text.txt); /*for IE6,也可以用一张图片URL,是否存在这文件无所谓*/
background-attachment:fixed; /* 这句是关键之一:一定要fixed,不能用scroll */
第二种:css方法
body{margin:0;}
#test{display:block; bottom:3px; right:3px; width:130px; position:fixed;}
/* 以下是写给IE6的 */
* html body{height:100%; overflow-y:auto;}
* html #test{position:absolute; right:18px;}
* html{overflow-x:auto; overflow-y:hidden;}
原理:
1、position定位,如果前面的父元素都没有position的话,那么该position定位元素是相对于html的,
注意!是相对html,而不是body
2、html滚动条隐藏,使用body滚动条overflow:auto模拟html滚动条。
3、body层高度100%,当html不设置height高度的时候,除了IE6外,body处的百分比高度是无效的(这算是利用了IE6的bug吧!)
第三种:jQuery方法
var otop = $("#sub_nav").offset().top;
$(window).scroll(function(){
var scroll_top = parseInt($(window).scrollTop());
if( scroll_top > otop ){
if ($.browser.msie && ($.browser.version == "6.0") && !$.support.style) {
$("#sub_nav").css({position:"absolute", top:$(window).scrollTop()+"px"});
}else{
$("#sub_nav").css({position:"fixed", top:"0px"});
}
}else{
$("#sub_nav").css({position:"static", top:""});
}
});
上面的sub_nav是一个层,随着页面向下滚动,当此水平条接触浏览器的上边缘时,水平条独立出来,不跟随滚动条滚动了
第四种:插件方法
jquery插件:任意位置浮动固定层(09-11-05更新插件)
第五种:js函数
<div class="float" id="float"> 我是个腼腆羞涩的浮动层… </div>
var $smartFloat = function(elements) {
var position = function(element) {
var top = element.getPosition().y, pos = element.getStyle("position");
window.addEvent("scroll", function() {
var scrolls = this.getScroll().y;
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.setStyles({
position: "fixed",
top: 0
});
} else {
element.setStyles({
top: scrolls
});
}
}else {
element.setStyles({
position: "absolute",
top: top
});
}
});
};
if ($type(elements) === "array") {
return elements.each(function(items) {
position(items);
});
} else if ($type(elements) === "element") {
position(elements);
}
};
//绑定
$smartFloat($("float"));
浮动层固定兼容IE6 position:fixed的最佳解决方案的更多相关文章
- 浮动层-JS兼容IE6
//引用jquery 包/*orderBycat 与 orderBycatHead 双层浮动*/ $(window).scroll(function () { var top = $(window). ...
- 解决IE6下浮动层固定定位的经典方法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 解决IE6下固定定位问题 使用position:fixed
IE6浏览器有太多的bug让制作网页的人头疼.这篇文章介绍的是介绍的是如何解决IE6不支持position:fixed;属性的办法. 如果我们需要做某个元素始终位于浏览器的底部,不会因为浏览器窗口的缩 ...
- 解决 IE6 position:fixed 固定定位问题
#e_float{ _position:absolute; _bottom:auto; _right:50%; _margin-right:-536px; _top:expression(eval(d ...
- 完美解决 IE6 position:fixed 固定定位问题
关于 position:fixed; 属性 生成绝对定位的元素,相对于浏览器窗口进行定位. 元素的位置通过 “left”, “top”, “right” 以及 “bottom” 属性进行规定. pos ...
- IOS系统不兼容position: fixed;属性的解决方案
position: fixed;属性在IOS系统手机上会有很明显的抖动,解决方式: 只需要在中间部分外层div添加css样式position:fixed;top:50px; bottom:50px;o ...
- IE6 position:fixed bug hack方式
/* IE6浏览器的特有方法 */ /* 修正IE6振动bug */ * html,* html body{background-image:url(about:blank);background-a ...
- 清除浮动小记,兼容Ie6,7
.clearfix { *zoom:1;} .clearfix:after{clear:both; display:block; height:0; visibility:hidden; line-h ...
- IE6下Png透明最佳解决方案(推荐) Unit PNG Fix
引自:http://www.yeeyan.org/articles/view/98510/67784 网络上解决IE6下Png透明解决方案有很多,例如 IE PNG Fix from TwinHeli ...
随机推荐
- 有用的BitConverter
肯定有用的到的转换,记录下来. ///double =>ieee754 double d = 0.12345; byte[] IEEE754 = BitConverter.GetBytes(d) ...
- 【27前端】字体图标 Font Face
设计师做的高保真原型图,难免会用到艺术字体. 采用切片的方式,简单,粗暴,节省时间.除了retina屏其它兼容性也是一流.但是在修改的时候,会花很大的力气.即使只是修改文字大小,也需要重新切图,更别说 ...
- android的color整理(一)
很全面的颜色收集方便以后使用. <!-- 白色 --> <color name="ivory">#fffff0</color> <!-- ...
- [Linked List]Linked List Cycle,Linked List Cycle II
一.Linked List Cycle Total Accepted: 85115 Total Submissions: 232388 Difficulty: Medium Given a linke ...
- zoj1183 Scheduling Lectures
这道题题意不想说了,跑了640ms,感觉水过去了,应该能通过单调队列优化,很长时间没碰已经不知道怎么写了,就说说现在的写法吧. 状态定义很关键:dp[i][j]把前j个topic放在前i堂课. 因为这 ...
- css3之3D翻牌效果
最近一直在学css3,发现他真的是越来越牛逼.现在的css3已经不在是以前的css了,它能做出的功能效果是我们没法想象的了.它可以实现flash,可以制作一些js能做出来的效果,还可以写出ps做出 ...
- CI的扩展机制
CI的扩展机制 在熟悉了CI的源码之后,它的简单明了的代码风格很有趣,这篇文章看看在CI是如何实现扩展的. 扩展包 扩展是为了完成特定的功能,在CI中,扩展包的开发只能在application/lib ...
- 解决Admob Banner首次展示不显示的问题
Admob banner在第一次虽然加载成功了,但是却不显示.然后等待60秒刷新自动刷新,banner就能正常显示. 如果你没遇到过这种情况,那可能你用的不是集成在play-services里的库,因 ...
- poj3507---去掉最小值和最大值
#include <stdio.h> #include <stdlib.h> int main() { ) { ,max=,min=,t; ; i<; i++) { sc ...
- Android-Tab单选控件
今天看到项目中有一个控件写得很美丽,据说是github上开源的控件,地址没找到,例如以下图所看到的,很常见的效果,几个tab页面来回切换: 转载请标明出处:http://blog.csdn.net/g ...