【发布时间】:2011-07-25 09:30:50
【问题描述】:
我的页面中有一个包含动态数据的跨度,采用ellipsis 样式。
.my-class
{
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
width: 71px;
}
<span id="myId" class="my-class"></span>
document.getElementById('myId').innerText = "...";
我想在此元素工具提示中添加相同的内容,但我希望它仅在内容较长且省略号出现在屏幕上时出现。
有什么办法吗?
激活ellipsis时浏览器会抛出事件吗?
*浏览器:Internet Explorer
【问题讨论】:
-
请记住,
text-overflow:ellipsis;在 Firefox 中根本不起作用——请参阅此问题了解更多信息:stackoverflow.com/questions/4927257/… -
我只需要做类似的事情。到目前为止,根据this answer 检查
element.offsetWidth < element.scrollWidth是否有效。 -
后人注意:
text-overflow:ellipsis;现在可以在 Firefox 中使用;它是在 Firefox 7(2011 年 9 月发布)中添加的。
标签: javascript html css tooltip ellipsis