How to create fa-bars animated menu
Question
I’m trying to animate my i class fa bars
so that the hamburger menu rotates and crosses on click.
I haven’t been able to find a way to animate it, so found this.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,
initial-scale=1">
<style>
.container {
display: inline-block;
cursor: pointer;
}
.bar1, .bar2, .bar3 {
width: 35px;
height: 5px;
background-color: #333;
margin: 6px 0;
transition: 0.4s;
}
. change .bar1 {
-webkit-transform: rotate(-45deg) translate(-9px, 6px);
transform: rotate(-45deg) translate(-9px, 6px);
}
.change .bar2 {opacity: 0;}
.change .bar3 {
-webkit-transform: rotate(45deg) translate(-8px, -8px);
transform: rotate(45deg) translate(-8px, -8px);
}
</style>
</head>
<body>
<div class="container" onclick="myFunction(this)">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div> <script>function myFunction(x) {
x.classList.toggle("change");
}
</script>
</body>
</html>
The problem is, how do I implement it on my site so that it replaces the fa-bars and functions in the same capacity?
0
css, html, javascript
3 years
2020-04-02T12:51:14-05:00
2020-04-02T12:51:14-05:00 0 Answers
98 views
0
Leave an answer