2013-01-01 70 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。您能否提供一個跨瀏覽器的版本本準則跨瀏覽器修復,上滾動功能

+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以來所有的瀏覽器正常工作。它不會在IE6中運行,因爲它不支持position:fixed