我試圖讓一個div出現在某個按鈕被按下並讓它在類.hidden(它隱藏了div)之間切換。我試圖通過添加一個轉換來爲此設置動畫,但由於某種原因,它被隱藏的事實打亂了它。總之,我想知道是否有辦法讓隱藏狀態和可見狀態之間的轉換動畫化。如何在javascript和css中切換到「隱藏」時切換
var main = function() {
$("#myMenu").css("height", window.innerHeight);
$("#myMenu").css("width", window.innerWidth);
}
$(document).ready(main);
.toggle {
font-size: 20px;
margin: 20px;
margin-top: 30px;
display: block;
position: fixed;
top: 0;
right: 0;
z-index: 100;
}
.hidden {
visibility: none;
display: none;
}
.menu {
background-color: red;
position: fixed;
top: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!--contains hamburger-->
<div class="toggle">
<a id="tButton" href="javascript:void(0);" onclick="toggleNav()">☰</a>
</div>
<!--actual mobile menu-->
<div id="myMenu" class="menu hidden">
<ul>
<li><a onclick="toggleNav()">Home</a>
</li>
<li><a onclick="toggleNav()">Events</a>
</li>
<li><a onclick="toggleNav()">About</a>
</li>
<li><a onclick="toggleNav()">Volunteer</a>
</li>
<li><a onclick="toggleNav()">Contact</a>
</li>
</ul>
</div>
<script>
function toggleNav() {
$("#myMenu").toggleClass("hidden");
if ($("#myMenu").hasClass("hidden")) {
$("#tButton").text(String.fromCharCode(9776));
} else {
$("#tButton").text(String.fromCharCode(10005));
}
}
</script>
fadeToggle ---的slideToggle ... – DaniP
這一工程,但如果我想要什麼菜單開始作爲隱藏? –
在CSS上啓動它爲'display:none' – DaniP