chrome不认documentElement.scrollTop
生活随笔
收集整理的這篇文章主要介紹了
chrome不认documentElement.scrollTop
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
視頻課堂https://edu.csdn.net/course/play/7621
在頁面顯示浮動層時,IE、Firefox下都能顯示正常,但Chrome下出現了浮動層永遠顯示在上面,經過仔細分析,發現Chrome對document.documentElement.scrollTop的識別會出現誤差。不過加上document.body.scrollTop后,則顯示正常。
由于document.documentElement.scrollTop和document.body.scrollTop在標準模式或者是奇怪模式下都只有一個會返回有效的值,所以都加上也不會有問題(看來上面的問題是Chrome可能把文檔當作非標準文檔來解析了)。
解決方案1:
if (document.documentElement && document.documentElement.scrollTop) document.getElementById("poster").style.top = document.documentElement.scrollTop + "px"; else if (document.body) document.getElementById("poster").style.top = document.body.scrollTop+"px";
解決方案2:
document.getElementById("poster").style.top = document.documentElement.scrollTop +document.body.scrollTop+ "px";
總結
以上是生活随笔為你收集整理的chrome不认documentElement.scrollTop的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 从70元到60亿,可以进来看看这篇文章
- 下一篇: 深入javascript中的exec与m