我编辑你的一点点(大约 4-6 行)
首先将您slidePanel
的链接和在某些 div 中向上滑动的链接包装起来
<div> <!-- new line-->
<a href="#" onclick="slideDiv(this);"> <p class="blueText">A post title here :</p> </a>
<div class="slidePanel">
<div class="contentFade">
<p class="p1">Some text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my page</p>
</div>
<!-- end contentFade -->
</div>
<!-- end sldiePanel -->
<!-- end post1 -->
</div><!-- new line-->
<div><!-- new line-->
<!-- second post to show issue -->
<a href="#" onclick="slideDiv(this);"> <p class="blueText">A post title here :</p> </a>
<div class="slidePanel">
<div class="contentFade">
<p class="p1">Some text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my pageSome text I will be displaying on my page</p>
</div>
<!-- end contentFade -->
</div>
<!-- end sldiePanel -->
<!-- end post1 -->
</div><!-- new line-->
然后为你的js代码
function slideDiv(elem) {
if ($(".slidePanel").is(":visible"))//new line
$(".slidePanel").slideUp();//new line
if ($(".slidePanel",$(elem).parent()).is(":visible")) {//notice the $(elem).parent()
$(".contentFade",$(elem).parent()).animate(
{
opacity: "0"
},
600,
function(){
$(".slidePanel",$(elem).parent()).slideUp();
}
);
}
else {
$(".slidePanel",$(elem).parent()).slideDown(600, function(){
$(".contentFade",$(elem).parent()).animate(
{
opacity: "1"
},
600
);
});
}
}