Tag: dotdotdot

如何使用dotdotdot实现Read More和Read less?

使用jQuery dotdotdot插件,当有大量文本需要显示时,我希望同时显示和隐藏 全部内容。 “ 更多”按钮工作得很好,但我还没有找到一种方法将 返回到它的原始显示。 请注意,这不仅仅是关于如何使用dotdotdot扩展截断的字符串,因为它包含Less按钮重新截断长字符串。 这是我的代码 : $(function() { $(“div.ellipsis-text”).dotdotdot({ after: ‘a.more’, callback: dotdotdotCallback }); $(“div.ellipsis-text”).find(“a”).click(function() { if ($(this).text() == “More”) { var div = $(this).closest(‘div.ellipsis-text’); div.trigger(‘destroy’).find(‘a.more’).hide(); div.css(‘max-height’, ”); $(“a.less”, div).show(); } else { $(this).text(“More”); $(this).closest(‘div.ellipsis-text’).css(“max-height”, “50px”).dotdotdot({ after: “a”, callback: dotdotdotCallback }); } }); function dotdotdotCallback(isTruncated, originalContent) { if (!isTruncated) { $(“a”, this).remove(); […]