Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if ellipsis is being displayed when using -webkit-line-clamp for multiline ellipsis

Tags:

css

We are using the multiline CSS ellipsis as per https://css-tricks.com/line-clampin/. We want to detect if the ellipsis is being displayed, and make a decision to show the tooltip based on whether ellipsis is being displayed.

I tried to compare the offsetWidth and the scrollWidth, but those values are the same regardless of whether the ellipsis are displayed. If anyone has hints, your help is greatly appreciated. Thank you.

like image 507
AshD Avatar asked Sep 08 '18 04:09

AshD


1 Answers

Use offsetHeight and scrollHeight when it gets line-clamped.

const isEllipsisActive = (element: HTMLElement) => {
     return element.offsetHeight < element.scrollHeight;
}
like image 121
Our_Benefactors Avatar answered Jun 01 '23 12:06

Our_Benefactors