나는 fudgey의 링크에서 부분적으로 가져온이 jQuery를 구성했습니다. 안타깝게도 div의 높이를 .height()와 비교해야하기 때문에 em 대신 px를 사용합니다. 그것은 또한 기능에 그것을 만들기 위해 더 예뻐질 수 있지만 그것은 작동합니다 :)
$(document).ready(function() {
var maxlines = 12;
var lineheight = 15; // line height in 'px'
var maxheight = (maxlines * lineheight);
var allowedExtraLines = 3;
var showText = "Læs mere...";
var hideText = "Skjul tekst...";
$('.Truncate').each(function() {
var text = $(this);
if (text.height() > maxheight + allowedExtraLines * lineheight) {
text.css({ 'overflow': 'hidden', 'line-height': lineheight + 'px', 'height': maxheight + 'px' });
var link = $('<a href="#">' + showText + '</a>');
link.click(function (event) {
event.preventDefault();
if (text.css('height') == 'auto') {
$(this).html(showText);
text.css('height', maxheight + 'px');
} else {
//$(this).remove();
$(this).html(hideText);
text.css('height', 'auto');
}
});
var linkDiv = $('<div></div>');
linkDiv.append(link);
$(this).after(linkDiv);
}
});
});