有没有一种方法可以监听div的溢出事件?

3

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

有没有一种跨浏览器的方式来监听div元素的溢出?

类似于:$('#myDiv').bind("divOverflow", function(){alert('div溢出了!')})

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元素中的溢出?


0
你可以设置一个时间间隔并检查元素的 scrollHeight > offsetHeight。这方面没有内置事件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接