您可以打开ids
只是一个普通类名和附加一个处理它。
HTML:
<div class="box">
<p>About me</p>
</div>
<div class="dropbox">
<p>a wild potato appeared</p>
</div>
<div class="box">Projects</div>
<div class="dropbox">
<p>ja</p>
</div>
<div class="box">Websites</div>
<div class="dropbox">
<p>hey</p>
</div>
JS:
$(document).ready(function() {
$(".box").click(function() {
$(this).next('.dropbox').slideToggle("slow");
});
});
CSS:
* {
margin: 0 auto;
}
.box:first-child{
margin-top: 20px;
}
.box {
background-color: red;
max-width: 470px;
padding: 10px;
}
.box:hover {
background-color: yellow;
}
.dropbox {
max-width: 470px;
padding: 10px;
background-color: black;
display: none;
color: white;
}
Demo
而且顺便说一句你需要从左边的面板“Frameworks & Extensions”中选择你的小提琴中的jquery。
如果你想切换当前的Dropbox,你可以什么时候效果基本show其他只是做:
$(document).ready(function() {
var $dropBoxes = $('.dropbox');
$(".box").click(function() {
$dropBoxes.not($(this).next('.dropbox').slideToggle("slow")).slideUp('slow');
});
});
来源
2013-12-16 20:38:50
PSL
你忘了添加jQuery库,在这里修复你的jsfiddle http://jsfiddle.net/jkuVG/ 4/ –