【问题标题】:I.E css position problem when scrolling滚动时的IE css位置问题
【发布时间】:2010-08-06 10:40:00
【问题描述】:

我编写了一个 scrollSpy 函数,当用户在网页上上下滚动时检测他们的活动。

<script type="text/javascript">
function yPos() {
  var pos = 0;
  if( typeof( window.pageYOffset ) == 'number' ){
    //Netscape compliant
    pos = window.pageYOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    pos = document.body.scrollTop;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    pos = document.documentElement.scrollTop;
  }
  return pos;
}

window.onscroll = function(){
  var scrollPos  = yPos(), goTopElem = document.getElementById('scroll'), docBody = document.getElementsByTagName('body')[0];
  if(goTopElem && scrollPos  < 500 )                // user has scrolled up
     goTopElem.parentNode.removeChild(goTopElem);   // remove go to top link

  else if(scrollPos  > 500 && !goTopElem){ 
    var newDiv = document.createElement('DIV'), newLink = document.createElement('A'), txt = document.createTextNode('[back to top]'); 

     newLink.setAttribute('href','javascript:scroll(0,0);');
     newLink.appendChild(txt);   
     newDiv.setAttribute('id','scroll');  
     newDiv.appendChild(newLink);
     docBody.appendChild(newDiv);
   }
 } 
 </script> 
 <style type="text/css"> 
#scroll {
  position:fixed;   
  right: 0px; 
  bottom: 0px;
  display: block;
}  
  </style>

问题出在 Internet Explorer 上,当向下滚动时,窗口的右下角应该会出现一个链接——但这不会发生。 请帮忙。

【问题讨论】:

    标签: javascript css internet-explorer


    【解决方案1】:

    如果您使用的是 IE6 或旧版 IE7,则不支持 position: fixed。如果没有,请更新问题,详细说明您正在谈论的 IE 版本。

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 2019-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多