SVG hamburger menu button
How do I make an svg hamburger menu button?
An SVG "M" that compresses into a vertical line before transforming into an "X". Animated the SVG line element's x/y properties to achieve this effect. Using velocity for animations, had a few issues getting non-spring easing to work, but I still think it turned out alright.. What is a svg hamburger menu button? How do you make a svg hamburger menu button? This script and codes were developed by Eli Fitch on 28 October 2022, Friday.
SVG hamburger menu button - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>SVG hamburger menu button</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="btn"> <svg width="100px" height="100px" viewBox="0 0 100 100" fill="none" stroke="#000" id="velocitySvg"> <line id="1" x1="0" y1="100" x2="0" y2="0" stroke="#979797" stroke-width="2" stroke-linecap="round"/> <line id="2" x1="0" y1="0" x2="50" y2="65" stroke="#979797" stroke-width="2" stroke-linecap="round"/> <line id="3" x1="50" y1="65" x2="100" y2="0" stroke="#979797" stroke-width="2" stroke-linecap="round"/> <line id="4" x1="100" y1="0" x2="100" y2="100" stroke="#979797" stroke-width="2" stroke-linecap="round"/> </svg>
</div>
<div class="item item--1">Menu Item</div>
<div class="item item--2">Menu Item</div>
<div class="item item--3">Menu Item</div>
<div class="item item--4">Menu Item</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://julian.com/research/velocity/build/jquery.velocity.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
SVG hamburger menu button - Script Codes CSS Codes
body { overflow: hidden;
}
svg { overflow: visible; height: 100%; width: 100%;
}
.btn { padding: 20px; border: 1px solid #979797; width: 60px; height: 60px; border-radius: 6px; margin-bottom: 40px;
}
.item{ width: 200px; padding: 20px; font-family: sans-serif; font-weight: 100; text-align: center; position: relative; left: -400px;
}
.item:nth-child(even){ background-color: lightgray;
}
.item:nth-child(odd){ background-color: gray;
}
SVG hamburger menu button - Script Codes JS Codes
var open = false;
$('.btn').on('click',function(){ if(!open) { $("#1").velocity({x1: 50,x2: 50},{duration:200, easing: "easeOutBounce"}).delay(0).velocity({x1: 100, y1: 0, x2: 0, y2: 100},{duration:200, easing: "easeOutBounce"}); $("#2").velocity({x1: 50,x2: 50},{duration:200, easing: "easeOutBounce"}).delay(0).velocity({x1: 0, y1: 0, x2: 50, y2: 50, opacity: 0},{duration:200, easing: "easeOutBounce"}); $("#3").velocity({x1: 50,x2: 50},{duration:200, easing: "easeOutBounce"}).delay(0).velocity({x1: 50, y1: 50, x2: 100, y2: 0, opacity: 0},{duration:200, easing: "easeOutBounce"}); $("#4").velocity({x1: 50,x2: 50},{duration:200, easing: "easeOutBounce"}).delay(0).velocity({x1: 0, y1: 0, x2: 100, y2: 100},{duration:200, easing: "easeOutBounce"}); $('.item--1').delay(200).velocity({left: 0},{duration: 400, easing: "easeInSine"}) $('.item--2').delay(250).velocity({left: 0},{duration: 400, easing: "easeInSine"}) $('.item--3').delay(300).velocity({left: 0},{duration: 400, easing: "easeInSine"}) $('.item--4').delay(350).velocity({left: 0},{duration: 400, easing: "easeInSine"}) open = true; } else { $("#1").velocity("reverse").velocity({x1: 0, y1: 100, x2: 0, y2: 0},{duration:1000, easing: "spring"}); $("#2").velocity("reverse").velocity({x1: 0, y1: 0, x2: 50, y2: 65},{duration:1000, easing: "spring"}); $("#3").velocity("reverse").velocity({x1: 50, y1: 65, x2: 100, y2: 0},{duration:1000, easing: "spring"}); $("#4").velocity("reverse").velocity({x1: 100, y1: 0, x2: 100, y2: 100},{duration:1000, easing: "spring"}); $('.item--1').delay(350).velocity("reverse") $('.item--2').delay(300).velocity("reverse") $('.item--3').delay(250).velocity("reverse") $('.item--4').delay(200).velocity("reverse") open = false; }
})
/*var open = false;
$('#velocitySvg').on('click',function(){ if(!open) { $("#1").velocity({x1: 50,x2: 50},{duration:1000, easing: "spring"}); $("#2").velocity({x1: 50,x2: 50},{duration:1000, easing: "spring"}); $("#3").velocity({x1: 50,x2: 50},{duration:1000, easing: "spring"}); $("#4").velocity({x1: 50,x2: 50},{duration:1000, easing: "spring"}); $("#1").velocity({x1: 0, y1: 0, x2: 100, y2: 100},{duration:1000, easing: "spring"}); $("#2").velocity({x1: 0, y1: 0, x2: 50, y2: 50, opacity: 0},{duration:1000, easing: "spring"}); $("#3").velocity({x1: 50, y1: 50, x2: 100, y2: 0, opacity: 0},{duration:1000, easing: "spring"}); $("#4").velocity({x1: 100, y1: 0, x2: 0, y2: 100},{duration:1000, easing: "spring"}); open = true; } else { $("#1").velocity("reverse").velocity({x1: 0, y1: 100, x2: 0, y2: 0},{duration:1000, easing: "spring"}); $("#2").velocity("reverse").velocity({x1: 0, y1: 0, x2: 50, y2: 65},{duration:1000, easing: "spring"}); $("#3").velocity("reverse").velocity({x1: 50, y1: 65, x2: 100, y2: 0},{duration:1000, easing: "spring"}); $("#4").velocity("reverse").velocity({x1: 100, y1: 0, x2: 100, y2: 100},{duration:1000, easing: "spring"}); open = false; }
})*/
Developer | Eli Fitch |
Username | elifitch |
Uploaded | October 28, 2022 |
Rating | 3.5 |
Size | 2,602 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Flexslider thumbnail modification | 13,431 Kb |
Animated SVG Hexagon | 3,470 Kb |
Smiley guy | 3,845 Kb |
Canvas Hero Prototype | 3,070 Kb |
3D Retro Wave Spin | 5,825 Kb |
Gradient Borders Mixin | 3,394 Kb |
Vanilla JS sticky header | 1,944 Kb |
Mars | 3,817 Kb |
Diagonal gradient fill button | 4,860 Kb |
Cube of cubes | 6,112 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Fun animations with CSS3 | Minimalmonkey | 2,360 Kb |
Christ the Redeemer | Prashantsani | 2,208 Kb |
Cant get enough icecream in pure css3 | Melawire | 4,322 Kb |
CSS3 keyframe onload animation. | Samueljseay | 1,706 Kb |
Nested flexbox layout for library catalog | Boycetrus | 3,271 Kb |
Nested table email layout | Massimo-cassandro | 2,355 Kb |
TheCalendar.js | The-teacher | 6,330 Kb |
Bootstrap 3 Price Table | Honglio | 2,655 Kb |
Minimal Menu | Achudars | 3,430 Kb |
Loading Bar | Jaradlight | 2,333 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!