问题
I do not found the answer to this question, someone may have answered to this question yet, but:
how can I make dropdown menu for example to this animated menu: Animated transform from three lines menu to cross
I would want something like this, but with the above animated menu: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_mobile_navbar
Thanks for answers !
回答1:
Its so easy you can try to use this code from the link that you gave i took this for you :
function myFunction() {
var x = document.getElementById("myLinks");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
}
$(document).ready(function () {
$(document).on('click', ".lines-button", function () {
$('#overlay').show();
$('.lines-button').addClass('close');
});
$(document).on('click', ".lines-button.close", function () {
$('#overlay').hide();
$('.lines-button').removeClass('close');
});
});
body {
font-family: Arial, Helvetica, sans-serif;
}
body {
background: #000;
}
.lines-button {
position: relative;
float:right;
overflow: hidden;
margin: 0;
padding: 0;
width: 96px;
height: 50px;
font-size: 0;
text-indent: -9999px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
box-shadow: none;
border-radius: none;
border: none;
cursor: pointer;
-webkit-transition: background 0.3s;
transition: background 0.3s;
}
.lines-button:focus {
outline: none;
}
.lines-button span {
display: block;
position: absolute;
left: 18px;
right: 18px;
height: 8px;
background: white;
border-radius: 0.57143rem;
}
.lines-button span::before, .lines-button span::after {
position: absolute;
display: block;
left: 0;
width: 100%;
height: 8px;
background-color: #fff;
border-radius: 0.57143rem;
content:"";
}
.lines-button span::before {
top: -15px;
}
.lines-button span::after {
bottom: -15px;
}
.lines {
background: none;
}
.lines span {
-webkit-transition: background 0s 0.3s;
transition: background 0s 0.3s;
}
.lines span::before, .lines span::after {
-webkit-transition-duration: 0.3s, 0.3s;
transition-duration: 0.3s, 0.3s;
-webkit-transition-delay: 0.3s, 0s;
transition-delay: 0.3s, 0s;
}
.lines span::before {
-webkit-transition-property: top, -webkit-transform;
transition-property: top, transform;
}
.lines span::after {
-webkit-transition-property: bottom, -webkit-transform;
transition-property: bottom, transform;
}
.lines.close {
background: none;
}
.lines.close span {
background: none;
}
.lines.close span::before {
top: 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
.lines.close span::after {
bottom: 0;
-webkit-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
.lines.close span::before, .lines.close span::after {
-webkit-transition-delay: 0s, 0.3s;
transition-delay: 0s, 0.3s;
}
.mobile-container {
max-width: 480px;
margin: auto;
background-color: #555;
height: 500px;
color: white;
border-radius: 10px;
}
.topnav {
overflow: hidden;
background-color: #333;
position: relative;
}
.topnav #myLinks {
display: none;
}
.topnav a {
color: white;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
display: block;
}
.topnav a.icon,.topnav button.icon{
background: black;
display: block;
position: absolute;
right: 0;
top: 0;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.active {
background-color: #4CAF50;
color: white;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
</head>
<body>
<!-- Simulate a smartphone / tablet -->
<div class="mobile-container">
<!-- Top Navigation Menu -->
<div class="topnav">
<a href="#home" class="active">Logo</a>
<div id="myLinks">
<a href="#news">News</a>
<a href="#contact">Contact</a>
<a href="#about">About</a>
</div>
<button class="icon lines-button lines" onclick="myFunction()"> <span></span>
</button>
</div>
<div style="padding-left:16px">
<h3>Vertical Mobile Navbar</h3>
<p>This example demonstrates how a navigation menu on a mobile/smart phone could look like.</p>
<p>Click on the hamburger menu (three bars) in the top right corner, to toggle the menu.</p>
</div>
<!-- End smartphone / tablet look -->
</div>
</body>
</html>
来源:https://stackoverflow.com/questions/61919859/how-to-make-dropdown-mobile-menu-with-animated-three-lines