例如:
.container{ width:200px; height:16px;overflow:hidden;font-size:13px; }
<div class="container">
I want to know this sentence's width is bigger than my container div's width
</div>
如果容器
内的字符串更长
,有没有办法可以将字符串从头到尾设置动画并一次又一次循环
。但如果更短,就留下来吧!!
[更新]
按照Don的方式
,字符串宽度的内部元素
与容器的宽度
相等,并且字符串被包装。那么,我该如何如何将内部元素的宽度
设置为字符串的实际长度
!?
非常感谢!
最佳答案
你可以用尺子解决这个问题: 将
<div id="ruler" style="display: none">
I want to know this sentence's width is bigger than my container div's width
</div>
现在您可以获取字符串的长度并将其与 .container 的长度进行比较
if ($("#ruler").width() > $(".container").width()) {
//what ever you want to do if the string is to long
}
关于jquery - Jquery中如何检查字符串是否比容器div的宽度长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5018248/