我编写了一个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,当向下滚动链接应该出现在窗口的右下角时 - 但这不会发生。 请帮忙。
答案 0 :(得分:1)
如果您正在谈论IE6或较旧的IE7,则不支持position: fixed
。如果没有,请更新问题,详细说明您正在谈论的IE版本。