答案 0 :(得分:0)
我已经重新设计了一个旧项目中的代码,以便为您提供有关您所使用的功能的开始
$(function() {
$(document).click(function() {
$('.wrapper-dropdown').toggleClass('active');
});
});
.wrapper-dropdown {
position: relative;
width: 300px;
margin: 0 auto;
padding: 12px 15px;
background: #fff;
box-shadow: 0 1px 0 #c6bba2;
cursor: pointer;
outline: none;
color: #c6bba2;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.wrapper-dropdown:after {
content: "+";
position: absolute;
right: 15px;
color: #c6bba2;
}
.wrapper-dropdown .dropdown {
position: absolute;
top: 100%;
left: 0;
right: 0;
padding: 0;
margin: 0;
background: #fff;
border: 1px solid #c6bba2;
border-top: none;
border-bottom: none;
list-style: none;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
/* Hiding */
max-height: 0;
overflow: hidden;
}
.wrapper-dropdown .dropdown li {
padding: 0 10px;
}
.wrapper-dropdown .dropdown li a {
display: block;
text-decoration: none;
color: #c6bba2;
padding: 10px 0;
transition: all 0.3s ease-out;
border-bottom: 1px solid #c6bba2;
}
.wrapper-dropdown .dropdown li:last-of-type a {
border: none;
}
.wrapper-dropdown .dropdown li i {
margin-right: 5px;
color: inherit;
vertical-align: middle;
}
.wrapper-dropdown .dropdown li:hover a {
color: #57a9d9;
}
.wrapper-dropdown.active {
background: #c6bba2;
box-shadow: none;
border-bottom: none;
color: white;
}
.wrapper-dropdown.active:after {
border-color: #c6bba2 transparent;
}
.wrapper-dropdown.active .dropdown {
border-bottom: 1px solid #c6bba2;
max-height: 400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="dd" class="wrapper-dropdown" tabindex="1">Size & Fit
<ul class="dropdown">
<li><a href="#">Size 8</a></li>
<li><a href="#">Size 10</a></li>
<li><a href="#">Size 12</a></li>
</ul>
</div>
您添加的选项越多,您调整.wrapper-dropdown.active .dropdown
希望这有帮助!