2013-01-01 1 views
2
window.onscroll = function() 
{ 
if(window.XMLHttpRequest) { 
var bodyId=document.getElementById('bodymain'); 
    if (bodyId.scrollTop > 187) { 
    //make some div's position fixed 
    } else { 
      //make some div's position absolute 

    } 
} 
} 

이 코드는 Chrome 용으로 잘 작동하지만 IE9에서는 작동하지 않습니다. 이 코드크로스 브라우저 수정, OnScroll 기능

+0

XHR 기능을 확인하는 이유는 무엇입니까? – jeremy

답변

3
window.onscroll = function() { 
    var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; 
    if (scrollTop > 187) { 
     //make some div's position fixed 
    } else { 
     //make some div's position absolute 
    } 
} 

Fiddle

의 크로스 브라우저 버전을 제안 할 수 있습니다 이것은 IE7 이후의 모든 브라우저에서 잘 작동합니다. position:fixed을 지원하지 않기 때문에 IE6에서는 실행되지 않습니다.