当我点击一个按钮来显示另一个div时,如何隐藏div?当我点击一个锚点按钮时,显示一个div并隐藏其他值
我只想一次显示一个div,当你点击一个按钮并用滑动效果隐藏其余部分时,我希望我能让自己明白。这是我第一次在这里问问题,我的英语不是很好:C
我现在有这个,它的可怕的哈哈我不是很好。
$(document).ready(function() {
$('.button1').on('click', function() {
$('.div1').slideToggle();
});
$('.button2').on('click', function() {
$('.div2').slideToggle();
});
$('.button3').on('click', function() {
$('.div3').slideToggle();
});
$('.button4').on('click', function() {
$('.div4').slideToggle();
});
});
* {
margin: 0;
padding: 0;
}
.toggler-wrap {
background-color: royalblue;
}
.buttondiv {
display: flex;
justify-content: space-around;
padding: 20px;
}
.buttons {
padding: 10px 30px;
display: block;
border: 3px solid whitesmoke;
color: whitesmoke;
text-align: center;
font-family: cursive;
text-decoration: none;
border-radius: 5px;
font-weight: bold;
}
.buttons:hover {
background-color: whitesmoke;
color: royalblue;
}
.divs {
height: 400px;
color: whitesmoke;
font-family: cursive;
text-align: center;
line-height: 400px;
font-size: 500%;
display: none;
}
.div1 {
background-color: orange;
}
.div2 {
background-color: green;
}
.div3 {
background-color: red;
}
.div4 {
background-color: purple;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="Toogler.css">
<title></title>
</head>
<body>
<div class="toggler-wrap">
<div class="buttondiv">
<a href="#" class="button1 buttons">button 1</a>
<a href="#" class="button2 buttons">button 2</a>
<a href="#" class="button3 buttons">button 3</a>
<a href="#" class="button4 buttons">button 4</a>
</div>
<div class="div1 divs">Div1</div>
<div class="div2 divs">Div2</div>
<div class="div3 divs">Div3</div>
<div class="div4 divs">Div4</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript" src="Toogler.js"></script>
</body>
</html>
非常感谢所有的,这是非常有用的。 – marlonspr