我有以下代码:
JS:
<script type="text/javascript">
$(document).ready(function(){
$('[href=#del]').click(function(){
var myParent = $(this).closest('.box');
myParent.slideUp(800, function(){
myParent.remove();
}); }); });
</script>
CSS:
h1 {
font-family: Arial;
font-weight: 300;
color: #444;
}
a {
color: #fff;
font-family: Arial;
text-decoration:none;
margin-left: 5px;
}
.box {
width: 150px;
height: 300px;
margin-right: 5px;
}
.box1 {
background-color: red;
float: left;
display: inline-block;
}
.box2 {
background-color: green;
float: left;
display: inline-block;
}
.box3 {
background-color: blue;
float: left;
display: inline-block;
}
.box4 {
background-color: black;
float: left;
display: inline-block;
}
.container {
width: 660px;
margin: 50px auto;
}
HTML:
<div class="container">
<div class="box box1"><a href="#del">Toggle</a></div>
<div class="box box2"><a href="#del">Toggle</a></div>
<div class="box box3"><a href="#del">Toggle</a></div>
<div class="box box4"><a href="#del">Toggle</a></div>
</div>
问题:
如何使用一个带有 Toggle 的锚标签,当点击它时,所有四个框的大小都会从高度 300px 减小到 150px?我现在拥有的代码只是将其删除,但我需要将框从 300 像素缩小到 150 像素。当再次单击它时,它应该返回到 300px。