0
我有多个可折叠的div像这样检测是否格是在浏览器窗口中可见
+--------------+
| Div 1 |
+--------------+
| Div 2 |
+--------------+
| Div 3 |
+--------------+
现在,当我点击它扩展
问题的div之一:我如何检测扩展DIV是在浏览器窗口(底部边框)上展开?
我有多个可折叠的div像这样检测是否格是在浏览器窗口中可见
+--------------+
| Div 1 |
+--------------+
| Div 2 |
+--------------+
| Div 3 |
+--------------+
现在,当我点击它扩展
问题的div之一:我如何检测扩展DIV是在浏览器窗口(底部边框)上展开?
你可以试试这个,这是一个未经测试的想法,因此可能需要进行一些修改。
var div1Height = $("#div1").height();
var div2Height = $("#div2").height();
var div3Height = $("#div3").height();
var windowSize = $(window).height();
//assign function for on click (you'll want to change this)
$("#div1, #div2, #div3").click(function(e){
if(div1Height > windowSize){
//assuming div1 is at the top
console.log("div 1 passing extents");
}
if((div2Height + parseInt($("#div2").position().top) > windowSize){
console.log("div 2 passing extents");
}
if((div3Height + parseInt($("#div3").position().top) > windowSize){
console.log("div 3passing extents");
}
});
你的意思是div是浏览器窗口过度的吗?越界?从视口中出来? – Sander
你的div有ID吗? –
看到这篇文章:[http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport](http://stackoverflow .com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-current-viewport) – expertCode