题
我的网页上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
并与含有其余部分的类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