I have a span that is dynamically filled with content. When the content reaches the width of 500px, I need to read the content that is of 300px.
The content can be one line or multiple lines.
Any solution?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The grabbag.js library has a method just for this purpose*.
There is not much documentation, but there is a function in there called grabbag.measure.crop that you can use to crop a string to a given dimension. I’ve written a little JS fiddle that will demonstrate how to use the library, but the basics go like this:
Where ele is a DOM element to “steal” styling from. Result will contain a string that just barely fits under the number of pixels given.
Hope that helps.