positon:fixed 让html元素脱离文档流固定在浏览器的某个位置
网页中经常会有浮动的导航条会用到这种定位模式,但是ie6下并不兼容这种定位
浮动导航条的样式,重要的是position:fixed;bottom:60px;(浮动导航底部距离窗口底部60px)
复制代码 代码如下:
.floating_9677{position:fixed; z-index:961; bottom:60px;}
ie6下positon:fixed不起作用,只能靠js来实现了,首先在ie6下需要将position设置为absolute
复制代码 代码如下:
position:fixed;bottom:60px;_position:abosulte;
给浮动元素加一个属性标识,js通过这个属性能找到这些浮动元素。tag=floatnavigator
工作中浮动导航条主要通过top或者bottom来定位。
复制代码 代码如下:
//ie6兼容position:fixed
function fixedpositioncompatibility(){
//判断是否ie6浏览器
if( $.browser.msie || parseint($.browser.version,10) var vavigators = $([tag='floatnavigator']);
if(!navigators.length)return;
//判断每个浮层是靠顶部固定还是底部固定
$.each(navigators, function(){
this.top = $(this).css(top);
this.bottom = $(this).css(bottom);
this.istop = this.top == auto ? false : true;
});
window.attachevent(onscroll, function(){
var scrolltop = document.documentelement.scrolltop || document.body.scrolltop;
$.each(navigators, function(){
this.style.top = this.istop ? scrolltop + parseint(this.top) + px : scrolltop + $(window).height() - $(this).outerheight() - parseint(this.bottom) + px;
});
});
}
}
