Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to create Newton’s Sun and Moon Loading Animation using HTML CSS and JS

    5 July 2025

    How to create Headphone Animation using HTML CSS and JS

    1 July 2025

    How to create Netflix Intro Animation using HTML and CSS

    29 June 2025
    Facebook X (Twitter) Instagram YouTube Telegram Threads
    Coding StellaCoding Stella
    • Home
    • Blog
    • HTML & CSS
      • Login Form
    • JavaScript
    • Hire us!
    Coding StellaCoding Stella
    Home - JavaScript - How to make Slide-out Navigation with GSAP 3 using HTML CSS & JavaScript
    JavaScript

    How to make Slide-out Navigation with GSAP 3 using HTML CSS & JavaScript

    Coding StellaBy Coding Stella27 September 2024Updated:15 December 2024No Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Let’s create a Slide-out Navigation using GSAP 3, HTML, CSS, and JavaScript. This project will feature a smooth, animated slide-out navigation menu that appears when triggered by a button, enhancing the user experience with dynamic, modern interactions.

    We’ll use HTML to structure the menu, CSS for basic styling, and GSAP 3 in combination with JavaScript to control the animations for the slide-out effect.

    Let’s dive into building the Slide-out Navigation with GSAP 3. Whether you’re a beginner or an experienced developer, this project offers a great way to practice creating sleek, responsive navigation with smooth animations. Let’s add some motion to our menus!

    HTML :

    This HTML creates a slide-out navigation menu with a clickable SVG button. When clicked, it reveals icons for different sections (like notifications or settings). The GSAP library is used to animate the menu sliding in and making the icons visible.

    <!DOCTYPE html>
    <html lang="en" >
    <head>
      <meta charset="UTF-8">
      <title>Slide-out Navigation with GSAP 3</title>
      <link rel="stylesheet" href="./style.css">
    
    </head>
    <body>
    
    <header>
      <!-- Menu button, using an SVG image as an icon -->
      <img class="activator" id="activator" src="//s.svgbox.net/hero-outline.svg?fill=fff#menu-alt-1" alt="">
    
      <!-- Navigation menu with icons, each linking to different sections -->
      <nav>
        <ul>
          <li><a href="#"><img src="//s.svgbox.net/hero-outline.svg?fill=805ad5#bell"></a></li>
          <li><a href="#"><img src="//s.svgbox.net/hero-outline.svg?fill=805ad5#beaker"></a></li>
          <li><a href="#"><img src="//s.svgbox.net/hero-outline.svg?fill=805ad5#chat"></a></li>
          <li><a href="#"><img src="//s.svgbox.net/hero-outline.svg?fill=805ad5#cloud-download"></a></li>
          <li><a href="#"><img src="//s.svgbox.net/hero-outline.svg?fill=805ad5#cog"></a></li>
        </ul>
      </nav>
    </header>
    
      <!-- External JavaScript libraries for animations and GSAP functionality -->
      <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/gsap.min.js'></script>
      <script src='https://cdnjs.cloudflare.com/ajax/libs/gsap/3.5.1/CSSRulePlugin.min.js'></script>
      <script  src="./script.js"></script>
    
    </body>
    </html>

    CSS :

    This CSS styles a webpage to have a centered layout with dark-themed elements. The body fills the entire viewport, has no margins, and displays content using CSS grid. The header section contains a clickable element (with the class .activator) styled as a circular button that changes its background color on hover. The nav element has a rounded shape and uses clip-path for hidden content that can be revealed during animation. Inside nav, there is a horizontal list (ul) of links (a), each containing an image. The images are initially invisible and positioned slightly to the left, making them ready for animation when hovered or triggered by JavaScript.

    body {
      margin: 0;
      height: 100vh;
      background: #171717;
      color: white;
      display: grid;
      place-content: center;
    }
    
    header {
      display: flex;
    }
    
    header .activator {
      padding: 1em;
      border-radius: 100%;
      cursor: pointer;
    }
    
    header .activator:hover {
      background: #1e2129;
    }
    
    img {
      width: 100%;
      max-width: 45px;
    }
    
    ul {
      list-style-type: none;
      margin: 0;
      padding: 0;
    }
    
    nav {
      background: #292e38;
      border-radius: 0 5em 5em 0;
      padding: 0.5em;
      clip-path: ellipse(50% 50% at -50% 50%);
    }
    
    nav ul {
      display: flex;
    }
    
    nav ul li a {
      display: block;
      padding: 0.5em;
      margin: 0 0.5em;
      border-radius: 50%;
    }
    
    nav ul li a:hover {
      background: #323844;
    }
    
    nav ul li a img {
      opacity: 0;
      transform: translateX(-10px);
    }

    JavaScript:

    This code animates an HTML element using GSAP (GreenSock Animation Platform). It targets an element with the ID ‘activator’ and creates a timeline (tl) with animations: changing the background color and border radius of the activator, expanding a nav element using clipPath, and making images in the nav appear with opacity and a sliding effect. Initially, the animation is paused. When the activator is clicked, it toggles the animation, either playing it forward or reversing it based on the toggle state.

    var card = document.getElementById('activator');
            var tl = gsap.timeline({defaults: {ease: "power2.inOut"}})
    
            var toggle = false;
    
            tl.to('.activator', {
                background: '#805ad5',
                'borderRadius': '5em 0 0 5em'
            });
            tl.to('nav', {
                'clipPath': 'ellipse(100% 100% at 50% 50%)'
            }, "-=.5")
            tl.to('nav img', {
                opacity: 1,
                transform: 'translateX(0)',
                stagger: .05
            }, "-=.5")
            tl.pause();
    
            card.addEventListener('click', () => {
                toggle = !toggle;
                if (toggle ? tl.play() : tl.reverse());
            })

    In conclusion, creating a Slide-out Navigation using GSAP 3, HTML, CSS, and JavaScript has been an exciting and rewarding project. By combining these technologies, we’ve developed a sleek, modern menu with smooth, animated transitions that enhance user experience and interactivity.

    If your project has problems, don’t worry. Just click to download the source code and face your coding challenges with excitement. Have fun coding!

    navigation menu
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleHow to make Glowing Snake Game using HTML CSS & JavaScript
    Next Article How to make Glowing Tube Loader using HTML & CSS
    Coding Stella
    • Website

    Related Posts

    JavaScript

    How to create Newton’s Sun and Moon Loading Animation using HTML CSS and JS

    5 July 2025
    JavaScript

    How to create Headphone Animation using HTML CSS and JS

    1 July 2025
    JavaScript

    How to create Order Confirm Animation using HTML CSS and JS

    27 June 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Trending Post

    Master Frontend in 100 Days Ebook

    2 March 202420K Views

    How to make Modern Login Form using HTML & CSS | Glassmorphism

    11 January 202418K Views

    How to make I love you Animation in HTML CSS & JavaScript

    14 February 202416K Views

    How to make Valentine’s Day Card using HTML & CSS

    13 February 202412K Views
    Follow Us
    • Instagram
    • Facebook
    • YouTube
    • Twitter
    ads
    Featured Post

    How to make Glassmorphism Login Form using HTML & CSS

    14 January 2024

    How to make Magic Social Share Menu using HTML CSS and JS

    14 April 2025

    How to create Smooth Image Slider using HTML CSS & JavaScript

    30 January 2025

    How to Create Skeleton Loading Animation in HTML & CSS

    12 January 2024
    Latest Post

    How to create Newton’s Sun and Moon Loading Animation using HTML CSS and JS

    5 July 2025

    How to create Headphone Animation using HTML CSS and JS

    1 July 2025

    How to create Netflix Intro Animation using HTML and CSS

    29 June 2025

    How to create Order Confirm Animation using HTML CSS and JS

    27 June 2025
    Facebook X (Twitter) Instagram YouTube
    • About Us
    • Privacy Policy
    • Return and Refund Policy
    • Terms and Conditions
    • Contact Us
    • Buy me a coffee
    © 2025 Coding Stella. Made with 💙 by @coding.stella

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Looks like you're using an ad blocker. We rely on advertising to help fund our site.
    Okay! I understood