Last active
February 1, 2022 05:23
-
-
Save mttmzr/a1df98c8a9367e7eaa3cc7f61cd93f33 to your computer and use it in GitHub Desktop.
Simple javascript function to check if an element is truncated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if an element is truncated. | |
* | |
* CSS to be used: | |
* .truncate { | |
* width: 250px; | |
* white-space: nowrap; | |
* overflow: hidden; | |
* text-overflow: ellipsis; | |
* } | |
* | |
* See http://stackoverflow.com/a/27155342/2131573 | |
* and https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/ | |
*/ | |
function isTruncated(el) { | |
return el.scrollWidth > el.clientWidth | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It does not work in Firefox