GithubHelp home page GithubHelp logo

lineclamp's People

Contributors

dependabot[bot] avatar rentectravis avatar tvanc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

martinmalinda

lineclamp's Issues

possible performance improvement

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)

  1. receives a string with length 100
  2. checks if 100 passes, if yes returns
  3. if not tries 50
    4a) if 50 passess, tries 75, if passes, tries 87, keeps going until the delta is > 1. When the delta is 1, returns
    4b) if 50 does not pass, tries 25, then 12, then maybe 18 and so again until delta is 1.

This algorithm would radically reduce the amount of checks for long texts

usage for toggling?

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.