私はdiv
単純なテキストを含んでいます。showMore
リンク付きのテキストを 3 行だけ表示する必要があります。showMoreリンクをクリックすると、その中のすべてのテキストをshowLess
リンクで表示する必要があります。現在overflow
、これを達成するためにプロパティを使用しています。"showMore"
しかし、テキストの直後にリンクを表示する必要があるという小さな問題があります。では、テキスト内にハイパーリンクを配置するにはどうすればよいでしょうか?
マイコード
jQuery(document).ready(function () {
jQuery('.showMore').click(function (event) {
var contentDiv = jQuery('.contentDiv');
contentDiv[0].style.height = 'auto';
jQuery(event.target).hide();
jQuery('.showLess').show();
});
jQuery('.showLess').click(function (event) {
var contentDiv = jQuery('.contentDiv');
var lineHeight = getLineHeight(contentDiv[0]);
contentDiv[0].style.height = lineHeight * 3 + 'px';
jQuery(event.target).hide();
jQuery('.showMore').show();
});
});
<!doctype html>
<html>
<body >
<div>
<div class = "contentDiv">
some content <br r1<br> r2<br> r3 <br> r4<br> r5
</div>
<a href = '#' class = "showMore">Show More</a>
<a href = '#' class = "showLess">Show Less</a>
</div>
</body>
</html>
.contentDiv a {
float : right;
}
.contentDiv {
overflow: hidden;
height:3.6em;
background:#ccc;
font-size : 12pt ;
font-family :Courier;
}
.showMore {
float: right;
}
.showLess {
position: relative;
float: right;
display : none;
margin-bottom : 5px
}