fixed定位(ie6下模拟fixed定位) 和标准布局的切换

来源:互联网 发布:js使input不可编辑 编辑:程序博客网 时间:2024/05/21 08:41
fixed定位(ie6下模拟fixed定位) 和标准布局的切换,历经一天才发现ie6这个问题,废话不说直接看代码
第一步: 防止抖动:
var isIE6 = !!window.ActiveXObject && !window.XMLHttpRequest;
if (isIE6&&document.body.currentStyle.backgroundAttachment!== 'fixed'){
html=document.getElementsByTagName('html')[0],
html.style.backgroundImage = 'url(about:blank)';
html.style.backgroundAttachment = 'fixed';
}
第二步 ie6下使用expression定义top,或者left例如
h3.fixed{position:fixed; top:0px;_position:absolute;_top:expression(documentElement.scrollTop);}
注意ie6下此元素不能再定定义其他class 例如<h3 class="ul_wrap"></h3>这样的写的话expression就不起作用了啊

第三步 绑定事件,加上你的逻辑。
具体我的测试代码在这里;有疑问的可以联系我 qq:38926469
$(window).scroll(function(){var sc_top=$(this).scrollTop();//获取滚动条的距离;var top=$("h3").offset().top;if((sc_top>top)&&(sc_top<(top+$("h3").outerHeight(true)))){$("h3").addClass("fixed");}else{$("h3").removeClass().removeAttr("style");//ie6必须删除style,应为ie6下 expression就是相当于在该元素加了一个style;}});


$(window).scroll(function(){var sc_top=$(this).scrollTop();//获取滚动条的距离;var top=$("h3").offset().top;if((sc_top>top)&&(sc_top<(top+$("h3").outerHeight(true)))){$("h3").addClass("fixed");}else{$("h3").removeClass().removeAttr("style");//ie6必须删除style,应为ie6下 expression就是相当于在该元素加了一个style;}});






0 0
原创粉丝点击