3

可能重复:
如何检测 div 元素中的溢出?

是否有跨浏览器的方式来收听 div 溢出?

就像是:$('#myDiv').bind("divOverflow", function(){alert('div overflowed!')})

4

2 回答 2

2

您可以通过将 scrollHeight 与 clientHeight 进行比较来做到这一点。

<script type="text/javascript">
function GetContainerSize ()
{
    var container = document.getElementById ("tempDiv");
    var message = "The width of the contents with padding: " + container.scrollWidth + "px.\n";
    message += "The height of the contents with padding: " + container.scrollHeight + "px.\n";

    alert (message);
}
</script>

有关更多信息:如何检测 div 元素中的溢出?

于 2012-10-02T03:00:00.463 回答
0

您可以设置一个间隔并检查元素的scrollHeight > offsetHeight. 对此没有内置事件。

于 2012-10-02T03:00:06.357 回答