2011-04-23 44 views
0

我試圖在同一頁面上爲多個div添加滑動效果,但一次只有一個,這裏是我的代碼:爲同一頁面上的多個元素添加滑動效果

 
$(function(){ 
    $(".child").hide(); 
    $(".parent").hover(
     function(){ $(".child").slideDown('slow'); }, 
     function(){ $(".child").slideUp('slow'); } 
    ); 

});

和HTML

<div class="parent"> 
    <strong>This would display some content that I can click on</strong> 
</div> 
<div class="child"> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
</div>
<div class="parent"> 
    <strong>This would display some content that I can click on</strong> 
</div> 
<div class="child"> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
    This expands across the whole window and is fixed to the bottom<br/> 
</div>

問題是,我想只有一個div來同時滑動不是所有

回答

0

你可以這樣做:

 
$(".parent").hover(
     function(){ $(this).next(".child").slideDown('slow'); }, 
     function(){ $(this).next(".child").slideUp('slow'); } 
    ); 
 
0

你可以使用:first:last選擇一次一個,並打開它。

謝謝..

相關問題