How to check a string longer than the width of a container div in jQuery?

eg:

.container{ width:200px; height:16px;overflow:hidden;font-size:13px; }

<div class="container">
I want to know this sentence width is bigger than my container div width
</div>

and if the string inside containeris equal much longer, there is a way I can animate the string from begin to the end and loop again and again. But in short, just stay!

[update]

With Don way, inner element with string widthaways are equal width of container, and the string was wrapped. So, how can I do that inner element widthI was string actual length?

Many thanks!

+3
source share
3 answers

I think you should put your line in the inner member (eg div, p, h1, ...), and then compare it to the width of the container.

+2
source

you can solve this using the ruler: add to your site that <div>

<div id="ruler" style="display: none">
   I want to know this sentence width is bigger than my container div width
</div>

.container

if ($("#ruler").width() >  $(".container").width()) {
  //what ever you want to do if the string is to long
}
+3

, div, _ .

jQuery jQscroller , div.

, , - span, . $('span').outerWidth() $('#container').width(), , . span , . ( )

+1

Source: https://habr.com/ru/post/1792558/


All Articles