Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 在jquery中,如何检测子元素溢出父元素(顶部、左侧、右侧和底部)? var元素=document.querySelector(父级); if((element.offsetHeight_Jquery Ui - Fatal编程技术网

Jquery ui 在jquery中,如何检测子元素溢出父元素(顶部、左侧、右侧和底部)? var元素=document.querySelector(父级); if((element.offsetHeight

Jquery ui 在jquery中,如何检测子元素溢出父元素(顶部、左侧、右侧和底部)? var元素=document.querySelector(父级); if((element.offsetHeight,jquery-ui,Jquery Ui,此解决方案仅检测右侧和底部。我需要检测全侧溢出状态。这是工作小提琴: 如果父项有多个子项,则仅检查第一个子项。我需要检查所有孩子的状态。我该怎么做?我的小提琴:jsfiddle.net/mpanuraj/SbhqG/5 var element = document.querySelector(parent); if((element.offsetHeight < element.scrollHeight) || (element.offsetWidth < element.scr

此解决方案仅检测右侧和底部。我需要检测全侧溢出状态。

这是工作小提琴:


如果父项有多个子项,则仅检查第一个子项。我需要检查所有孩子的状态。我该怎么做?我的小提琴:jsfiddle.net/mpanuraj/SbhqG/5
var element = document.querySelector(parent);

if((element.offsetHeight < element.scrollHeight) || (element.offsetWidth < element.scrollWidth)) {
    element.style.borderColor = "Red";
}
else {
    element.style.borderColor = "white";
}
var p = $('#parent');
var c = $('#child');
var p_o = p.offset();
var c_o = c.offset();
var p_o_right = parseInt(p_o.left + p.width(), 10);
var p_o_bottom = parseInt(p_o.top + p.height(), 10);
var c_o_right = parseInt(c_o.left + c.width(), 10);
var c_o_bottom = parseInt(c_o.top + c.height(), 10);

$(function () {
    if (p_o.top > c_o.top || p_o_right < c_o_right || p_o_bottom < c_o_bottom || p_o.left > c_o.left) {
        alert('child overflows');
    } else {
        alert('child inside');
    }
});
#child {
    top: 10px;
    left: 20px;
}