JS (or JQuery): Find the point where a line wraps

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FLEB
    New Member
    • Aug 2008
    • 30

    JS (or JQuery): Find the point where a line wraps

    Is there a built-in function or a simplified method to tell where a given line of text wraps/will wrap in a given container (the container is fixed-width)? I want to chop off and add an ellipsis to some text at the point where it exceeds one line.

    My best idea so far is to just create a dummy container with the same specs, off-screen or invisible, and feed words into it one-by-one, then return where the container changes height. This just seems like the "brute force" long way around the problem, but I don't know if there's a better way.
  • rnd me
    Recognized Expert Contributor
    • Jun 2007
    • 427

    #2
    that's the trick i use, and it works.

    there really is no other good way since firefox 3 zooms everything, making
    calculations next to impossible.

    i would write it into a reusable function that you can pass text and a style attrib to, and get back the width.

    makes a nice addition to your script library.

    Comment

    • FLEB
      New Member
      • Aug 2008
      • 30

      #3
      Excellent. Thanks.

      _______________ _______________ __

      Comment

      Working...