간단한 텍스트가 포함 된 div
이 있습니다. 나는 그 텍스트의 단지 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
}
당신은 당신이 질문을 편집하고 거기에 코드를 추가 할 – Pratik
개까지 무엇을했는지 코드를 게시 할 수 있습니다. – matthewpavkov
코드로 들어가서 내 잘못을 knoe하자. –