有没有办法听div溢出事件?

时间:2012-10-02 02:57:54

标签: javascript dom overflow

  

可能重复:
  How to detect overflow in div element?

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

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

2 个答案:

答案 0 :(得分: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>

了解更多信息:How to detect overflow in div element?

答案 1 :(得分:0)

您可以设置间隔并检查元素是否为scrollHeight > offsetHeight。没有内置事件。

相关问题