Created
November 15, 2021 17:43
-
-
Save interactiveRob/e2753d345a17cf7cb06696acceb54435 to your computer and use it in GitHub Desktop.
Javascript check text width exceeds container
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
| function setOverflowStyle(bar) { | |
| if (!exists(bar)) return; | |
| let parts = bar.parts; | |
| if (!parts.length) return; | |
| [...parts].map((part) => { | |
| let width = part.dataset.amount / this.total; | |
| if (part.offsetWidth < part.scrollWidth) { | |
| part.classList.add('has-number-outside'); | |
| let content = part.innerHTML; | |
| part.innerHTML = `<span class="c-stat-bar__data">${content}</span>`; | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment