Determine if an HTML element's content overflows

前端 未结 6 999
误落风尘
误落风尘 2020-11-22 05:19

Can I use JavaScript to check (irrespective of scrollbars) if an HTML element has overflowed its content? For example, a long div with small, fixed size, the overflow proper

6条回答
  •  借酒劲吻你
    2020-11-22 05:57

    I don't think this answer is perfect. Sometimes the scrollWidth/clientWidth/offsetWidth are the same even though the text is overflow.

    This works well in Chrome, but not in IE and Firefox.

    At last, I tried this answer: HTML text-overflow ellipsis detection

    It's perfect and works well anywhere. So I choose this, maybe you can try, you won't disappoint.

提交回复
热议问题