【问题标题】:show the tooltip only when ellipsis is active仅当省略号处于活动状态时才显示工具提示
【发布时间】:2013-10-08 16:13:07
【问题描述】:

我有下一个 div:

 <div class="div-class" style="width:158px;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;" title=<%=myDesc%>

如何仅在省略号处于活动状态时显示工具提示?

我找到了这个功能

    function isEllipsisActive(e) {
     return (e.offsetWidth < e.scrollWidth);
}

但是知道自己用jsp和struts就不知道怎么用了

【问题讨论】:

标签: css


【解决方案1】:

试试这样的:

Working DEMO
Working DEMO - with tooltip

$(function() {
    $('div').each(function(i) {

         if (isEllipsisActive(this))
            //Enable tooltip 
         else
            //Disable tooltip
    });
});

function isEllipsisActive(e) {
     return (e.offsetWidth < e.scrollWidth);
}

【讨论】:

  • 我有一个愚蠢的问题 $(function...) 我应该把它放在哪里?
  • 如何用 TD 而不是 DIV 做同样的事情?你能举个例子吗?
【解决方案2】:

对于使用 qtip 的任何人(非常受欢迎)。 首先,为每个溢出的元素添加一个类。

<span class="ellipsis-text">Some very long text that will overflow</span>

然后,使用 jQuery 选择器选择多个此类元素,并将 qTip 插件(或任何其他想到的工具提示)应用于您的元素:

$('.ellipsis-text').each(function() {
    if (this.offsetWidth < this.scrollWidth) {
        $(this).qtip({
            content: {
                text: $(this).text()
            },
            position: {
                at: 'bottom center',
                my: 'top center'
            },
            style: {
                classes: 'qtip-bootstrap', //Any style you want
            }
        });
    }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-25
    • 1970-01-01
    • 2015-03-16
    • 2019-10-28
    • 2015-08-03
    • 2017-01-10
    • 2019-01-06
    相关资源
    最近更新 更多