【问题标题】:How to expand truncated text onclick by using dotdotdot?如何使用dotdotdot扩展截断的文本onclick?
【发布时间】:2013-09-25 22:03:53
【问题描述】:

我正在使用jQuery dotdotdot 截断插件dotdotdot.frebsite.nl

我想截断最多 2 行。当用户点击more 时,它必须显示全文(展开/去截断)。

到目前为止,我“只”设法截断我的文本。但不要“去截断”它。

这是我的代码:

<p class="truncate">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vitae tellus eu dui placerat interdum. Lorem ipsum dolor sit amet, consectetur adipiscing elit.<a class="read-more" href="#">more</a></p>

$(document).ready(function(){

    $('.truncate').dotdotdot({
        ellipsis     : '… ',
        watch        : true,
        wrap         : 'letter',
        height       : parseInt( $('.truncate').css('line-height'), 10) * 2, // this is the number of lines
        lastCharacter: {
            remove: [ ' ', ',', ';', '.', '!', '?' ],
            noEllipsis: []
        },
        after: "a.read-more"
    });


});

现场演示jsfiddle.net/NSnxe/1

【问题讨论】:

标签: javascript jquery dotdotdot


【解决方案1】:

您可以向 dotdotdot 发送销毁消息

$('a.read-more').on( 'click', function(event) {
    event.preventDefault();
    $(this).parent().trigger("destroy");
});

http://jsfiddle.net/bhlaird/C5Ent/

【讨论】:

  • @JoeAtzberger - 我没有 32,但它似乎在 33 中运行良好。你看到了什么行为?
  • 啊,我收回了。一定只是我的浏览器或我的大脑。现在看起来不错。
  • 不起作用:Uncaught TypeError: $(...).dotdotdot is not a function
  • @izogfif - 这个插件自 2013 年以来发生了重大变化,并且 dotdotdot.js 文件不再存在于它之前的位置。我建议查看dotdotdot.frebsite.nl 的当前使用情况
猜你喜欢
  • 2019-08-13
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 2016-07-13
  • 1970-01-01
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多