用jquery检测css text-overlow省略号 [英] detect css text-overlow ellipsis with jquery

查看:91
本文介绍了用jquery检测css text-overlow省略号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个小提琴

div{
    width:160px;
    text-overflow:ellipsis;
    overflow:hidden;
    white-space:nowrap;
    text-transform: uppercase;
}

我编辑了一个由其他人打造的小提琴,他们打算回答这个问题。

I edited a fiddle created by someone else who meant to answer this question.

这个答案是正确的,效果很好,但在一个案例中,这个方法效果不佳。如果文本应该是100%的框,省略号隐藏最后几个字母并添加...但是当你操纵css并删除溢出语句时,你会看到,大小适合。

This answer is right and works well, BUT in one case this does not work good. If the text should be 100% of the box ellipsis is hiding last few letters and adding "..." but when you manipulate the css and remove the overflow statement, then you will see, that the size fits.

所以这种方式并非100%可靠。但我需要100%工作。

请有人帮助我吗?

So this way is not 100% reliable. But i need a 100% working one.
please can someone help me?

推荐答案

我忘记了发布我的解决方案。

I forgot to post my solution.

现在我正在使用 el.scrollWidth> el.clientWidth; 并且它运行良好。

注意 el 在这种情况下不是jquery包装。

Now i'm using el.scrollWidth > el.clientWidth; and it's working well.
Note that el in this case is not jquery wrapped.

这篇关于用jquery检测css text-overlow省略号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆