jQuery는 첫 번째 주석에서 전체 페이지로 내려갑니다
문제
페이지에 10 개의 댓글 목록이 있습니다. 그들의 높이는 주석의 내용에 따라 다르기 때문에 알려져 있지 않습니다.
버튼을 클릭 할 때까지 첫 번째 주석 만 표시하는 가장 좋은 방법은 무엇입니까?이 시점에서 페이지에서 10 개의 댓글을 모두 공개하기 위해 미끄러 져 내려갑니다. 따라서 기본적으로 사용자는 하나의 주석 만 볼 수 있습니다.
감사!
해결책
jQuery :
$(function(){
$(".comments").not(":first").hide();
$("#btnViewAll").click(function(){
$(".comments").slideDown();
});
});
HTML :
<input type="button" id="btnViewAll" value="Show All Comments" />
<div class="comments">1 comment</div>
<div class="comments">2 comment</div>
<div class="comments">3 comment</div>
<div class="comments">4 comment</div>
<div class="comments">5 comment</div>
다른 팁
클래스에 버튼이있는 경우 viewMoreButton
그리고 a div
수업과 함께 moreComments
나머지 주석을 포함 하여이 스크립트를 사용할 수 있습니다.
$("div.moreComments").hide();
$(".viewMoreButton").click(function(){
$("div.moreComments").slideDown("fast");
$(this).remove();
}
또한 버튼 자체를 제거하지만 버튼을 원한다면 주석을 전환하려면 다음을 수행하십시오.
$("div.moreComments").hide();
$(".viewMoreButton").click(function(){
$("div.moreComments").slideToggle("fast");
}
제휴하지 않습니다 StackOverflow