jQuery+手风琴
时间: 2023-12-21 20:32:05 浏览: 105
以下是两种使用jQuery实现手风琴效果的例子:
1. 使用CSS3实现的手风琴特效:
```html
<!DOCTYPE html>
<html>
<head>
<title>手风琴特效</title>
<style>
.accordion {
width: 300px;
margin: 0 auto;
}
.accordion-item {
background-color: #f1f1f1;
border: 1px solid #ccc;
margin-bottom: 10px;
overflow: hidden;
transition: height 0.3s ease;
}
.accordion-item .title {
padding: 10px;
cursor: pointer;
}
.accordion-item .content {
padding: 10px;
display: none;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.title').click(function() {
$(this).next('.content').slideToggle();
$(this).parent().siblings().find('.content').slideUp();
});
});
</script>
</head>
<body>
<div class="accordion">
<div class="accordion-item">
<div class="title">标题1</div>
<div class="content">内容1</div>
</div>
<div class="accordion-item">
<div class="title">标题2</div>
<div class="content">内容2</div>
</div>
<div class="accordion-item">
<div class="title">标题3</div>
<div class="content">内容3</div>
</div>
</div>
</body>
</html>
```
2. 使用Bootstrap实现的手风琴折叠菜单:
```html
<!DOCTYPE html>
<html>
<head>
<title>手风琴折叠菜单</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
</head>
<body>
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
标题1
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
内容1
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
标题2
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
内容2
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
标题3
</button>
</h5>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">
内容3
</div>
</div>
</div>
</div>
</body>
</html>
```
阅读全文