2017-03-31 10 views
0

私はリンクが2つあり、両方とも異なるdivを示しています。私はすべての細かいトグルスライドを持っている。しかし、私はそれが必要なのは逆のトグル(開いている場合)を崩壊させることです。アコーディオンパネルがどのように機能するかと同様に(開いているパネルが閉じ、新たにトリガされたパネルが開く)Reveal toggle hide他のdiv jquery

ここで私は現在、ここ

//Left reveal toggle 
$(".left-reveal-toggle").on("click", function() { 
    $('.left-reveal-section').slideToggle("slow"); 
    $(".left-reveal-toggle").toggleClass("active"); 
}); 

//Right reveal toggle 
$(".right-reveal-toggle").on("click", function() { 
    $('.right-reveal-section').slideToggle("slow"); 
    $(".right-reveal-toggle").toggleClass("active"); 
}); 

を使用しているjQueryの作業JSFiddleリンクです: http://jsfiddle.net/wq73aeuh/1/

//Left reveal toggle 
 
$(".left-reveal-toggle").on("click", function() { 
 
    $('.left-reveal-section').slideToggle("slow"); 
 
    $(".left-reveal-toggle").toggleClass("active"); 
 
}); 
 

 
//Right reveal toggle 
 
$(".right-reveal-toggle").on("click", function() { 
 
    $('.right-reveal-section').slideToggle("slow"); 
 
    $(".right-reveal-toggle").toggleClass("active"); 
 
});
.left-panel { 
 
    min-height: 400px; 
 
    background: #31b9ce; 
 
    width: 50%; 
 
    float: left; 
 
    text-align: center; 
 
} 
 

 
.right-panel { 
 
    min-height: 400px; 
 
    background: #4f5cd6; 
 
    width: 50%; 
 
    float: left; 
 
    text-align: center; 
 
} 
 

 
.left-panel-reveal { 
 
    min-height: 400px; 
 
    background: #31b9ce; 
 
    width: 50%; 
 
    float: left; 
 
    text-align: center; 
 
} 
 

 
.right-panel-reveal { 
 
    min-height: 400px; 
 
    background: #4f5cd6; 
 
    width: 50%; 
 
    float: left; 
 
    text-align: center; 
 
} 
 

 
.hide { 
 
    display: none; 
 
} 
 

 
.clear { 
 
    clear: both; 
 
    font-size: 0px; 
 
    line-height: 0px; 
 
    display: block; 
 
} 
 

 
html, 
 
body, 
 
div, 
 
span, 
 
applet, 
 
object, 
 
iframe, 
 
h1, 
 
h2, 
 
h3, 
 
h4, 
 
h5, 
 
h6, 
 
p, 
 
blockquote, 
 
pre, 
 
a, 
 
abbr, 
 
acronym, 
 
address, 
 
big, 
 
cite, 
 
code, 
 
del, 
 
dfn, 
 
em, 
 
font, 
 
img, 
 
ins, 
 
kbd, 
 
q, 
 
s, 
 
samp, 
 
small, 
 
strike, 
 
strong, 
 
sub, 
 
sup, 
 
tt, 
 
var, 
 
b, 
 
u, 
 
i, 
 
center, 
 
dl, 
 
dt, 
 
dd, 
 
ol, 
 
ul, 
 
li, 
 
fieldset, 
 
form, 
 
label, 
 
legend, 
 
table, 
 
caption, 
 
tbody, 
 
tfoot, 
 
thead, 
 
tr, 
 
th, 
 
td { 
 
    margin: 0; 
 
    padding: 0; 
 
    border: 0; 
 
    outline: 0; 
 
    font-size: 100%; 
 
    vertical-align: baseline; 
 
    background: transparent; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
 
<div class="left-panel"> 
 
    <a href="#" class="left-reveal-toggle">Read more form left panel</a> 
 
</div> 
 

 
<div class="right-panel"> 
 
    <a href="#" class="right-reveal-toggle">Read more from right panel</a> 
 
</div> 
 

 

 
<div class="clear"></div> 
 

 

 
<div class="left-reveal-section hide"> 
 
    <div class="left-panel-reveal">left panel reveal content</div> 
 
    <div class="right-panel-reveal">left panel reveal content</div> 
 
</div> 
 

 

 
<div class="right-reveal-section hide"> 
 
    <div class="left-panel-reveal">right panel reveal content</div> 
 
    <div class="right-panel-reveal">right panel reveal content</div> 
 
</div>

+0

一般的なクラスを与え、いずれかを閉じてください。 – mplungjan

+0

を開く前に表示されます。こんにちは、もう少し詳しく教えてください。 – alexgomy

答えて

0

使用権で関数の最上部には: $ ( '.left-reveal-section')。slideUp( 'slow'); 左上の関数の先頭には: $( '。right-reveal-section')。slideUp( 'slow');

+0

ありがとうございます。それは素晴らしい作品です。私は1つの小さな問題があります。トグルリンクが押されると、代替のdivはあなたのslideUp関数ごとに崩壊しますが、トグルリンクにはまだ「アクティブ」クラスが追加されています。また、アクティブなクラスを削除する必要があります。更新されたJSFiddleがあります:http://jsfiddle.net/wq73aeuh/6/私の元の投稿から少し変更されている場合は申し訳ありません。 – alexgomy

+0

slideUp()の後に.toggleClass( "active")を追加しても問題ありません。 $( 'left-reveal-section')。slideUp( 'slow')。toggleClass( "active");右にも同じ –