简体   繁体   English

滚动时的IE CSS位置问题

[英]I.E css position problem when scrolling

I have written a scrollSpy function that detects user activity as they scroll up and down on a webpage. 我已经编写了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>

The problem is with internet explorer, when scrolling down a link should appear at the bottom right corner of your window - but this does not happen. 问题出在Internet Explorer上,当向下滚动时,链接应出现在窗口的右下角-但这不会发生。 Please help. 请帮忙。

If you are talking IE6 or an older IE7 then position: fixed is not supported. 如果您使用的是IE6或更旧的IE7,则不支持position: fixed If not, please update question with more specifics about which version of IE you are talking about. 如果不是,请更新有关您正在谈论的IE版本的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅在Wordpress中删除IE上的所有CSS动画 - Remove all CSS animations on I.E only in Wordpress 滚动时如何更新CSS位置 - How can I update css position when scrolling jQuery滚动到BOTTOM以加载新内容在Scrolling TOP上以相反的方式工作(即) - Jquery Scroll to BOTTOM to load new content is working in opposite way (i.e) on Scrolling TOP 尝试使用前端语言即 html、css 和 javascript 构建骰子游戏 - Trying to build a dice game using front end languages i.e html,css and javascript 如果我们有极长的水平滚动页面,如何在最后一个元素的末尾添加边距/填充,即空间? - How to add margin/padding i.e space right to the end of the last element if we have extremely long horizontal scrolling page? 预期为“;” IE中的异常(JavaScript,jQuery) - Expected ';' exception in I.E (JavaScript, jQuery) ScrollIntoView 在 reactjs 中不适用于 IE? - ScrollIntoView is not working for I.E in reactjs? Firefox和IE中的Jquery问题,但Chrome中没有 - Jquery issue in Firefox and I.e but not Chrome 如何在鼠标处于活动状态(即单击)时填充画布单元格中的颜色? - How to fill colors in the cells of canvas when mouse is active i.e clicked? 根据经度和纬度显示地图时如何更新地图,即; 从数据库中获取 - How to Update Map when Map show based on longitude and latitude i.e; fetch from database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM