tvanc / lineclamp Goto Github PK
View Code? Open in Web Editor NEWLimit an element's text to a given height or number of lines.
Limit an element's text to a given height or number of lines.
Thanks for the lib, it seems to do the job well in quite a few lines of JS.
But since it replaces the text in place, it makes it a bit harder to implement any kind of toggling functionality. If there was a function to return the clamped text instead of mutating the element, it would make the toggling easier to implement for me in Vue.
It would be nice if this was debounced.
https://github.com/tvanc/lineclamp/blob/master/src/LineClamp.js#L182
https://github.com/tvanc/lineclamp/blob/master/src/LineClamp.js#L262
at the moment the algorithm tries to cut one char after another until it can do its thing.
it's precise but it's heavy on the browser a bit, especially if the text is long and is expected to be longer than the expected amount of lines quite a bit
for 1000 char text that is likely to cut to 200, it does 800 measurements
what it could do instead (a divide and conquer solution)
This algorithm would radically reduce the amount of checks for long texts
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.