Thank you!! I have a first version of an implementation.
It can be seen in the attached video.
In my particular case, I have control of the HTML tags being used in the clamping text. With unexpected tags it gets more complex.
What I'm doing, in general terms is:
Hide overflow and use a max-height so in first loading it looks similar to the end result.
Separate by lines
Copy the line with the read more and position absolute on top of the line.
Move the overflown lines to a container with height 0
Transform the copied line to add the read more anchor and cut some text.
Fade in the "read more" line on top of the original.
When the anchor is clicked, fade-out the "read more" line and destroy it.
Tween the overflown lines to height auto (removing previously the max-height)
Revert the splittext to clean the dom.
Now things get messy with window resizing and all.
In case of unexpected tags, what I am thinking is that when the text is in "clamped" mode we don't need them as it's just a preview, so maybe I would strip all the tags, do the same operation, and when it is reverted to the original state we get the tags again.
One thing I noticed is that splittext is quite performant compared to other plugins that try to do the line-clamp, but of course, I'm using only part of it, as I only need to split the lines that I decided to clamp. With a lot of "read mores" in a website, would the performance of it suffer?
Thanks!
Gravació de pantalla 2021-05-14 a les 10.16.24.mov