how can i don't scroll long string by java script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mdharaghizadeh
    New Member
    • Oct 2013
    • 3

    how can i don't scroll long string by java script?

    Hello
    For example I have a div tag with long sting that string length is greater than one line:
    <div>
    qwekmlkmckskmkm lkmlcmdhuhjefuy bcvgdwelfjnfjev ljhjnfukfmkdfol ffneuwghqnnmlde lmkeienfbuyheuy tgpkrnbxhbybwij emncksmczmcigvk fmmfrkmfkcmsewl kfklcwehrunrjng t
    </div>

    browsers show it in one line with scroll,but I want to go to the next line when the sting arrive to the end of line.
    how can i do it with java script?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you can use CSS3’s word-break property.

    Comment

    • mdharaghizadeh
      New Member
      • Oct 2013
      • 3

      #3
      Thanks,but I know it,
      I want to do it by java script,because I want to continue the string in two lines later.
      Do you know that how can I do this?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        do you use a monospaced font?

        Comment

        • mdharaghizadeh
          New Member
          • Oct 2013
          • 3

          #5
          No,i don't use monospaced font.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            then you can’t AFAIK cut the string on the border of the element, as I do not know that it is possible to determine the width of a part (after a certain count of characters) of a string.

            the best bet would be a lucky guess based on the average length per character.

            though if you have lots of time, you could create an inline element, fill it with a character, check its length, fill it with the next character, check length again and repeat until you reach the element border.

            this is usually the job of the browser’s (HTML) rendering engine, which does not hook into the JS engine.
            Last edited by Dormilich; Oct 22 '13, 08:51 PM.

            Comment

            Working...