我正在看的codepen是這樣的。 http://codepen.io/candygong/pen/OMZqNZ如何讓標題在這個codepen中單獨工作
我想知道如何讓標題互相分開工作(例如,當你點擊一個另一個不滑落)。我知道我可以爲每個分配不同的類,但我想知道如何更有效地做到這一點,因爲我打算使用許多不同的頭文件,所以我想使用相同的類而不是爲每個實例創建一個類。
HTML代碼
<section>
<h1 class="question">q: what is this: hahahahplop?</h1>
<p class="answer"><span>a: someone laughing their head off!</span></p>
</section>
<section>
<h1 class="question">q: what is this: hahahahplop?</h1>
<p class="answer"><span>a: someone laughing their head off!</span></p>
</section>
CSS代碼
* {
margin: 0px;
padding: 0px;
}
body {
font-family: 'Roboto', sans-serif;
font-size: 20px;
color: #555;
}
section {
width: 5in;
margin: 24px auto;
text-align: center;
}
section h1.question {
color: white;
background-color: purple;
padding: 24px;
font-weight: 500;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
section p.answer {
border: 1px gray solid;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
padding:36px 0px;
}
Javascript代碼
$(function() {
console.log("ready");
$('section p.answer').hide();
$('section p.answer span').hide();
$('section h1.question').click(function(){
$('section p.answer').slideToggle();
$('section p.answer span').fadeToggle();
})
});
我知道你應該能夠使用這個關鍵字,但我一直無法得到它自己工作。