简体   繁体   English

无论如何,有没有检查元素是否溢出的信息?

[英]Is there anyway to check if an element has overflowed?

My site has numerous horizontal lists of words. 我的网站上有许多水平单词列表。 If the row has too many words to display in one row, it needs to display an "expand" button. 如果一行中有太多单词无法显示,则需要显示“展开”按钮。 Right now I determine if the row is full by adding up the estimated widths of the letters, but I am wondering if there is a simpler way to do this. 现在,我通过将字母的估计宽度相加来确定行是否已满,但是我想知道是否有更简单的方法可以做到这一点。 Is there any way using javascript or any library (especially YUI or jQuery) to determine if an element has overflow? 有没有办法使用JavaScript或任何库(尤其是YUI或jQuery)来确定元素是否溢出?

I assume you're referring to the overflow css property of DOM nodes. 我假设您是指DOM节点的溢出CSS属性。 In that case you could compare the scrollWidth as opposed to the clientWidth. 在这种情况下,您可以将scrollWidth与clientWidth进行比较。

Understanding offsetWidth, clientWidth, scrollWidth and -Height, respectively 分别了解offsetWidth,clientWidth,scrollWidth和-Height

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM