0
我已經做了一個下拉菜單使用Javascript和CSS的組合很好,但我希望顯示和隱藏菜單時的過渡效果,最好是下拉菜單時顯示,當它被隱藏時,它是一個俯臥撐......我如何整合這個?謝謝。如何在Javascript中切換「顯示」時添加下推/俯臥撐效果?
/* When the user clicks on the button,
toggle between hiding and showing the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
.dropbtn {
width: 80px;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
opacity: 0.95;
visibility: hidden;
display: block;
left: 0;
right: 0;
margin-left: auto;
margin-right: auto;
}
.dropbtn:hover,
.dropbtn:focus {
opacity: 1;
}
.dropdown {
position: relative;
display: inline-block;
width: 100%;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 100%;
margin-top: 5px;
overflow: auto;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
font-family: Century Gothic, Calibri, Cambria, sans-serif;
}
.dropdown a:hover {
background-color: #f1f1f1
}
.show {
display: block;
}
<div class="dropdown">
<img onclick="myFunction()" src="../images/logotestme.png" class="dropbtn" </img>
<div id="myDropdown" class="dropdown-content">
<a href="http://www.coopertimewell.com">Home</a>
<a href="http://www.coopertimewell.com/portfolio">Portfolio</a>
<a href="http://www.coopertimewell.com/contact">Contact</a>
<a href="http://www.coopertimewell.com/downloads">Downloads</a>
</div>
</div>