当前位置: 代码迷 >> ASP >> ie6下不兼容,求高手看这句js怎么改
  详细解决方案

ie6下不兼容,求高手看这句js怎么改

热度:301   发布时间:2013-11-01 14:43:02.0
ie6下不兼容,求高手看这句js如何改?
这代码在ie6下无效了。。请问如何弄才可以兼容?
就是下拉到一定距离,div会固定在浏览器顶部的。在ie6下失效。

<script type="text/javascript" src="jquery.min.js"></script>
<style>
.auto_fixed_top{width:300px;} 
.fixed_top{position:fixed;_position:absolute;top:0;z-index:900;}
</style>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
<div class="auto_fixed_top">

浮动固定浮动固定浮动固定浮动固定浮动固定浮动固定浮动固定

</div>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>

内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>
内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>内容<br>



<script type="text/javascript" >
$(function(){
if ($('.auto_fixed_top').size() > 0){
  $(window).scroll(function(){
     var scrollTop = parseInt($(document).scrollTop());
     if (scrollTop > 165){
        $('.auto_fixed_top').addClass('fixed_top');
     }else{
        $('.auto_fixed_top').removeClass('fixed_top');
     }
  });
}  
}); 

</script>

------解决方案--------------------
这样
.auto_fixed_top{width:300px;} 
.fixed_top{position:fixed;top:0;z-index:900;}


* html,* html body{background-image:url(about:blank);background-attachment:fixed} 
*html   .fixed_top{!important;position:absolute;
left:expression(eval(document.documentElement.scrollLeft));top:expression(eval(document.documentElement.scrollTop));} 

<script type="text/javascript" >
$(function(){
if ($('.auto_fixed_top').size() > 0){
  $(window).scroll(function(){
     var scrollTop = parseInt($(document).scrollTop());
     if (scrollTop > 165){
        $('.auto_fixed_top').addClass('fixed_top');
     }else{
        $('.auto_fixed_top').removeClass('fixed_top');
     }
  });
}  
}); 

</script>

------解决方案--------------------
因为IE6不支持position:fixed;样式,所以加上了这个class也不能固定的。所以需要用JS在触发scroll事件的时候计算确切的离页面顶部的值,然后更新scrolltop的值。
  相关解决方案