Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 div (就像一个层)并且对分辨率很小的访问者有问题。是否有简单的方法来测试 div 高度是否大于页面视口,如果是,将 div 移动到视口顶部?谢谢
试试这个:
(function () { var viewport = window.innerWidth, el = document.getElementById('myDiv'), widthDiv = el.style.width; if (widthDiv > viewport) { // Move the div higher el.style.zIndex = 999; } }())