【问题标题】:Is there a way to listen to a div overflow event? [duplicate]有没有办法监听 div 溢出事件? [复制]
【发布时间】:2012-10-02 11:00:06
【问题描述】:

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

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

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

【问题讨论】:

    标签: javascript dom overflow


    【解决方案1】:

    您可以通过比较 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?

    【讨论】:

      【解决方案2】:

      您可以设置一个间隔并检查元素是否为scrollHeight &gt; offsetHeight。没有内置事件。

      【讨论】:

        猜你喜欢
        • 2011-12-21
        • 2019-06-12
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-16
        • 2016-10-15
        相关资源
        最近更新 更多