MalikDzgn: Menu & Navigation
  • Jelajahi

    Copyright © MalikDzgn -

    Quickly update interesting info starting today

    Malikdzgn

    Malikdzgn
    Affichage des articles dont le libellé est Menu & Navigation. Afficher tous les articles
    Affichage des articles dont le libellé est Menu & Navigation. Afficher tous les articles

    mercredi 24 février 2021

    Responsive Hamburger Sidebar Navigation In Pure JavaScript – Omega.js

    Responsive Hamburger Sidebar Navigation In Pure JavaScript – Omega.js

     

    Responsive Hamburger Sidebar Navigation In Pure JavaScript – Omega.js

    Category: Javascript , Menu & Navigation | April 5, 2019
    AUTHOR:SelMaK-fr
    VIEWS TOTAL:2,885 views
    OFFICIAL PAGE:Go to website
    LAST UPDATE:April 5, 2019
    LICENSE:MIT

    Preview:

    Responsive Hamburger Sidebar Navigation In Pure JavaScript – Omega.js

    Description:

    Omega.js is a modern responsive mobile-first navigation system for the web.

    It uses CSS media queries to detect the screen size and collapse the regular navbar into a hamburger sidebar navigation (aka. off-canvas navigation).

    Click/tap the hamburger button to toggle the sidebar navigation sliding out from the edge of the screen.

    See also:

    How to use it:

    Import the Omega’s JavaScript and CSS files into the document.

    <link rel="stylesheet" href="assets/css/omega.css">
    <script src="assets/js/omega.js"></script>

    Create the HTML for the sidebar navigation and done.

    <div id="omega">
      <div id="omega-content">
        <nav>
          <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Blog</a></li>
            <li><a href="#">Contact</a></li>
          </ul>
        </nav>
        <div class="omega-links">
          <a href="#" class="button">Link 1</a>
          <a href="#" class="button button-outline ">Link 2</a>
        </div>
    
      </div>
      <button id="omega-button">&#9776;</button>
      <div id="omega-sidebar">
        <div id="omega-sidebar-header"></div>
        <div id="omega-sidebar-body"></div>
      </div>
      <div id="omega-overlay"></div>
    </div>
    Mobile-first Site Navbar With JavaScript & CSS

    Mobile-first Site Navbar With JavaScript & CSS

     

    Mobile-first Site Navbar With JavaScript & CSS

    Category: Javascript , Menu & Navigation | October 29, 2020
    AUTHOR:amateur-bot
    VIEWS TOTAL:946 views
    OFFICIAL PAGE:Go to website
    LAST UPDATE:October 29, 2020
    LICENSE:MIT

    Preview:

    Mobile-first Site Navbar With JavaScript & CSS

    Description:

    A modern, responsive, mobile-first site navigation that collapses nav items into a sidebar off-canvas menu on mobile.

    How to use it:

    1. Create a navbar from a nav list as follows:

    <nav class="navbar">
      <h1 class="navbar-brand">
        Navbar Here
      </h1>
      <ul class="nav-list">
        <li class="nav-item">
          <a class="nav-link active" href="#">
            home
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">
            JavaScript
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">
            CSS
          </a>
        </li>
      </ul>
    </nav>

    2. Insert a hamburger toggle button into the navbar.

    <div class="menu-toggle">
      <div class="hamburger">
      </div>
    </div>

    3. The core CSS styles for the sidebar off-canvas menu and menu toggler.

    .navbar {
      display: flex;
      justify-content: space-between;
      align-items: center;
      height: 8rem;
    }
    
    .navbar-brand {
      color: #ffffff;
      font-family: "Oswald", sans-serif;
      text-transform: uppercase;
    }
    
    .nav-list {
      list-style: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 80%;
      height: 100vh;
      background-color: #222222;
      padding: 4.4rem;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      z-index: 1250;
      text-transform: uppercase;
      transform: translateX(-100%);
      transition: transform 0.5s;
    }
    
    .nav-link:hover {
      border-bottom: 3px solid #ffffff;
    }
    
    .active {
      font-weight: 700;
      border-bottom: 3px solid #ffffff;
    }
    
    .open .nav-list {
      transform: translateX(0);
    }
    
    .menu-toggle {
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 3.2rem;
      height: 3.2rem;
      cursor: pointer;
      transition: all 0.5s ease-in-out;
    }
    
    .hamburger {
      width: 2.4rem;
      height: 3px;
      background-color: #ffffff;
      border-radius: 2px;
      border: none;
      transition: all 0.7s ease-out;
    }
    
    .hamburger::before,
    .hamburger::after {
      content: "";
      position: absolute;
      width: 2.4rem;
      height: 3px;
      background-color: #ffffff;
      border-radius: 2px;
      border: none;
    }
    
    .hamburger::before {
      transform: translateY(-8px);
    }
    
    .hamburger::after {
      transform: translateY(8px);
    }

    4. Setup menu toggle animations in the CSS.

    .open .hamburger {
      background: transparent;
    }
    
    .open .hamburger::before {
      transform-origin: (0, 0);
      transform: rotate(45deg);
    }
    
    .open .hamburger::after {
      transform-origin: (0, 0);
      transform: rotate(-45deg);
    }

    5. Apply the following CSS styles to the navbar when running on tablet or desktop.

    @media screen and (min-width: 768px) {
      .nav-list {
        position: initial;
        width: initial;
        height: initial;
        background-color: transparent;
        padding: 0;
        justify-content: initial;
        flex-direction: row;
        transform: initial;
        transition: initial;
      }
      .nav-link {
        margin-left: 4rem;
        font-size: 1.6rem;
        transition: all 0.1s;
      }
      .menu-toggle {
        display: none;
      }
    }

    6. The JavaScript to enable the hamburger menu toggler.

    const navbar = document.querySelector(".navbar");
    const menuToggle = document.querySelector(".menu-toggle");
    menuToggle.addEventListener("click", () => {
      navbar.classList.toggle("open");
    });
       CSS Only Responsive Sticky Navbar

    CSS Only Responsive Sticky Navbar

     

    CSS Only Responsive Sticky Navbar

    Category: CSS & CSS3 , Menu & Navigation , Recommended | June 25, 2020
    AUTHOR:sam-cross
    VIEWS TOTAL:2,579 views
    OFFICIAL PAGE:Go to website
    LAST UPDATE:June 25, 2020
    LICENSE:MIT

    Preview:

    CSS Only Responsive Sticky Navbar

    Description:

    responsive sticky navbar that coverts the nav items into a full-width off-canvas menu with a hamburger toggle button.

    Clicking/tapping the hamburger will slide the off-canvas menu out from the left side of the screen.

    Written in pure HTML and CSS/CSS3. Fully customizable by overriding the default variables in the main.scss.

    How to use it:

    1. Modify the CSS variables (colors, transitions, breakpoints) to fit your design.

    // main.scss
    $breakpoint_tablet: 680px;
    $breakpoint_desktop: 1040px;
    $max_header_width: 1200px;
    $color_background: #FAFAFA;
    $color_background_alt: #e0e5eb;
    $color_text: #121212;
    $color_text_alt: #36bae6;
    $color_border: #e0e5eb;
    $transition_link: .14s ease-in-out;
    $transition_anim: .22s ease-in-out;

    2. Compile the main.scss to main.css.

    sass /path/to/main.scss /path/to/main.css

    3. Load the main.css in the document.

    <link rel="stylesheet" href="main.css" />

    4. The HTML structure for the responsive sticky navbar.

    <header>
      <div class="container">
        <div class="logo">
          CSSScript
        </div>
        <input class="hamburger-button" type="checkbox" id="hamburger-button" />
        <label for="hamburger-button">
          <div></div>
        </label>
        <div class="menu">
          <nav>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Work</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
          </nav>
          <div class="buttons">
            <a href="#" class="button primary">Login</a>
            <a href="#" class="button">Settings</a>
          </div>
        </div>
      </div>
    </header>
    Responsive Navigation Bar With Flexbox And JavaScript – simply-nav

    Responsive Navigation Bar With Flexbox And JavaScript – simply-nav

     

    Responsive Navigation Bar With Flexbox And JavaScript – simply-nav

    Category: Javascript , Menu & Navigation | December 30, 2020
    AUTHOR:obscuredetour
    VIEWS TOTAL:329 views
    OFFICIAL PAGE:Go to website
    LAST UPDATE:December 30, 2020
    LICENSE:MIT

    Preview:

    Responsive Navigation Bar With Flexbox And JavaScript – simply-nav

    Description:

    A simple, lightweight, sticky, fully responsive, mobile-compatible navigation system built using JavaScript and CSS flexbox.

    It automatically collapses the navigation bar into an off-canvas hamburger navigation when the screen size is smaller than a specific width.

    Sticky navigation is supported as well. It means that you can stick the navigation bar to the top or bottom of the webpage.

    Basic usage:

    Import the necessary stylesheet and JavaScript into the document.

    <link rel="stylesheet" href="nav.css">
    <script src="simply-nav.js"></script>

    The necessary HTML structure for the navigation.

    <header class="nav-wrapper">
      <nav class="nav" role="navigation">
        <span class="toggleNav">
          <svg class="svg-hamburger" viewBox="0 0 1536 1280" xmlns="http://www.w3.org/2000/svg">
            <path class="svg-hamburger-path" d="M1536 1088v128q0 26-19 45t-45 19H64q-26 0-45-19t-19-45v-128q0-26 19-45t45-19h1408q26 0 45 19t19 45zm0-512v128q0 26-19 45t-45 19H64q-26 0-45-19T0 704V576q0-26 19-45t45-19h1408q26 0 45 19t19 45zm0-512v128q0 26-19 45t-45 19H64q-26 0-45-19T0 192V64q0-26 19-45T64 0h1408q26 0 45 19t19 45z"
                  fill="rgba(226, 241, 236, 20.85)" />
          </svg>
        </span> 
        <a class="nav__logo" href="#">
          <img class="logo logo-small" id="logo" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/JavaScript-logo.png/480px-JavaScript-logo.png" alt="Logo">
        </a>
        <ul class="nav__list" id="sideNav">
          <div class="nav__list-left">
            <a class="closeBtn">
              <svg class="svg-close" viewBox="0 0 1188 1188" xmlns="http://www.w3.org/2000/svg">
                <path class="svg-close-path" d="M1188 956q0 40-28 68l-136 136q-28 28-68 28t-68-28L594 866l-294 294q-28 28-68 28t-68-28L28 1024Q0 996 0 956t28-68l294-294L28 300Q0 272 0 232t28-68L164 28q28-28 68-28t68 28l294 294L888 28q28-28 68-28t68 28l136 136q28 28 28 68t-28 68L866 594l294 294q28 28 28 68z"
                      fill="rgba(226, 241, 236, 0.85)" />
              </svg>
            </a>
            <li>
              <a class="nav__item" href="#">Home</a>
            </li>
            <li>
              <a class="nav__item" href="#">Contact</a>
            </li>
            <li>
              <a class="nav__item" href="#">About</a>
            </li>
            <li>
              <a class="nav__item" href="#">Blog</a>
            </li>
            <li>
              <a class="nav__item" href="#">Works</a>
            </li>
          </div>
          <div class="nav__list-right">
            <div class="page__overlay"></div>
          </div>
        </ul>
      </nav>
    </header>

    To create a sticky navigation, just add the -sticky class to the nav wrapper.

    <header class="nav-wrapper -sticky">
      ...
    </header>

    Stick the navigation to the bottom using the -bottom class.

    <header class="nav-wrapper -sticky -bottom">
      ...
    </header>

    Changelog:

    v1.3.1 (12/30/2020)

    • Fixed overflow bug.

    v1.3.0 (12/26/2020)

    • Left & Right side layouts now supported. Right-side is now default.
    • Refactored some SCSS, cleaned up some styles, animations, & JS.
    • No longer maintaining standalone version (legacy version will remain).
    • Due to all of the above, DOM changes occurred and a version point bump.
    Off-canvas Side Navigation With Page Transitions

    Off-canvas Side Navigation With Page Transitions

     

    Off-canvas Side Navigation With Page Transitions

    Category: Javascript , Menu & Navigation , Recommended | February 7, 2018
    AUTHOR:Kyle Brumm
    VIEWS TOTAL:1,003 views
    OFFICIAL PAGE:Go to website
    LAST UPDATE:February 7, 2018
    LICENSE:MIT

    Preview:

    Off-canvas Side Navigation With Page Transitions

    Description:

    A modern sticky off-canvas sidebar navigation where the users are able to switch between page sections with a smooth transition effect by clicking nav links.

    How to use it:

    Create the off-canvas navigation that contains anchor links pointing to their page sections:

    <nav class="nav">
      <ul class="nav__list">
        <li class="nav__item"><a href="#">Section 1</a></li>
        <li class="nav__item"><a href="#">Section 2</a></li>
        <li class="nav__item"><a href="#">Section 3</a></li>
        ...
      </ul>
    </nav>

    Create a trigger element to toggle the off-canvas navigation.

    <div class="nav__bar">
      <a href="#" class="nav__trigger">
        <div class="bars"></div>
      </a>        
    </div>

    Create the sectioned content as follows:

    <main class="main">
    
      <section class="content">
    
        <article class="article">
          <a href class="article__title">Section 1</a>
          <p class="article__content">
            Section 1 Content
          </p>
        </article>
          
        <article class="article">
          <a href class="article__title">Section 2</a>
          <p class="article__content">
            Section 2 Content
          </p>
        </article>
    
        <article class="article">
          <a href class="article__title">Section 3</a>
          <p class="article__content">
            Section 3 Content
          </p>
        </article>
    
        ...
    
      </section>
    </main>

    The primary CSS/CSS3 styles.

    *, *:before, *:after {
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
    }
    
    html {
      font-family: "Open Sans", Helvetica, arial, sans-serif;
      color: #333333;
      background-color: #eeeeee;
    }
    
    body.is-froze {
      overflow: hidden;
      width: 100vw;
      height: 100vh;
    }
    
    h1, h2, h3, h4, h5, h6 { font-family: "Raleway", "Open Sans", sans-serif; }
    
    a {
      color: #333333;
      text-decoration: none;
    }
    
    img { max-width: 100%; }
    
    a {
      -webkit-transition: color 0.3s ease-in-out;
      transition: color 0.3s ease-in-out;
    }
    
    a:hover { color: #7d87a8; }
    
    .main {
      overflow: hidden;
      position: relative;
      width: 100%;
      width: calc(100% - 60px);
      height: 100vh;
      margin-left: 60px;
      background-color: #eeeeee;
      -webkit-transition: 0.55s cubic-bezier(0.645, 0.045, 0.355, 1);
      transition: 0.55s cubic-bezier(0.645, 0.045, 0.355, 1);
      -webkit-transform: scale(1) translate3d(0, 0, 0);
      transform: scale(1) translate3d(0, 0, 0);
      -webkit-clip-path: inset(0 0 0 0);
      clip-path: inset(0 0 0 0);
      will-change: width, height, opacity, transform, clip-path;
      z-index: 1;
    }
    
    .main.is-active {
      overflow: hidden;
      height: 100vh;
      width: 100vw;
      width: calc(100vw - 60px);
      pointer-events: none;
      opacity: 0.25;
      -webkit-transform: scale(0.9) translate3d(60%, 0, 0);
      transform: scale(0.9) translate3d(60%, 0, 0);
    }
    
    @media (min-width: 600px) {
    
    .main.is-active {
      -webkit-transform: scale(0.9) translate3d(40%, 0, 0);
      transform: scale(0.9) translate3d(40%, 0, 0);
    }
    }
    
    .main.is-transition-out {
      -webkit-clip-path: inset(0 0 0 100%);
      clip-path: inset(0 0 0 100%);
    }
    
    .article {
      padding: 1.5rem;
      position: relative;
    }
    
    @media (min-width: 600px) {
    
    .article { padding: 6vmin; }
    }
    
    .article:not(:last-of-type):after {
      content: '';
      position: absolute;
      bottom: 0;
      left: 1.5rem;
      width: 50px;
      height: 2px;
      background-color: #7d87a8;
    }
    
    @media (min-width: 600px) {
    
    .article:not(:last-of-type):after { left: 6vmin; }
    }
    
    .article__title {
      display: block;
      position: relative;
      font-family: "Raleway", "Open Sans", sans-serif;
      font-size: 1.5rem;
      color: #191b22;
    }
    @media (min-width: 600px) {
    
    .article__title { font-size: 3vmin; }
    }
    
    .article__title:hover { color: #7d87a8; }
    
    .article__time {
      display: block;
      position: relative;
      text-transform: uppercase;
      font-size: 0.8rem;
      margin-top: 1rem;
    }
    
    @media (min-width: 600px) {
    
    .article__time { font-size: 1.5vmin; }
    }
    
    .article__content {
      margin: 1rem 0 0;
      font-size: 1rem;
      line-height: 1.5;
    }
    
    @media (min-width: 600px) {
    
    .article__content { font-size: 2vmin; }
    }
    
    .nav__bar {
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      width: 60px;
      height: 100vh;
      border-right: 1px solid rgba(125, 135, 168, 0.25);
      background-color: #191b22;
      z-index: 99;
    }
    
    .nav__trigger {
      display: block;
      position: absolute;
      top: 50%;
      left: 16px;
      padding: 8px 0;
      margin-top: -10px;
      -webkit-transition: 0.2s ease-in-out;
      transition: 0.2s ease-in-out;
      z-index: 99;
    }
    
    .nav__trigger .bars { position: relative; }
    
    .nav__trigger .bars, .nav__trigger .bars:before, .nav__trigger .bars:after {
      width: 28px;
      height: 4px;
      background-color: #7d87a8;
      -webkit-transition: 0.2s ease-in-out;
      transition: 0.2s ease-in-out;
      border-radius: 4px;
    }
    
    .nav__trigger .bars:before, .nav__trigger .bars:after {
      content: '';
      display: block;
      position: absolute;
      top: 0;
      left: 0;
      will-change: transform;
    }
    
    .nav__trigger .bars:before {
      -webkit-transform: translateY(-8px);
      transform: translateY(-8px);
    }
    
    .nav__trigger .bars:after {
      -webkit-transform: translateY(8px);
      transform: translateY(8px);
    }
    
    .nav__trigger.is-active {
      -webkit-transform: rotate(-45deg);
      transform: rotate(-45deg);
    }
    
    .nav__trigger.is-active .bars:before, .nav__trigger.is-active .bars:after {
      -webkit-transform: translateX(0) rotate(-90deg);
      transform: translateX(0) rotate(-90deg);
    }
    
    .nav {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: #191b22;
      z-index: 0;
    }
    
    .nav__list {
      overflow: hidden;
      position: absolute;
      top: 50%;
      left: 0;
      width: 100%;
      margin: 0;
      padding-left: 60px;
      list-style: none;
      font-family: "Raleway", "Open Sans", sans-serif;
      -webkit-transform: translateY(-50%);
      transform: translateY(-50%);
    }
    
    .nav__list .nav__item { padding: 0.5rem 1rem; }
    
    @media (min-width: 600px) {
    
    .nav__list .nav__item {
      width: 33.3333333333%;
      padding: 0.5rem 1rem;
    }
    }
    
    .nav__list a {
      display: inline-block;
      color: #7d87a8;
      font-size: 1rem;
      line-height: 1.5;
    }
    
    .nav__list a:hover { color: #b1b7cb; }
    
    .nav__list a.is-active { color: #d2d5e1; }
    @media (min-width: 600px) {
    
    .nav__list a { font-size: 1.5rem; }
    }

    Load the necessary classList.js and smoothScroll libraries in the document.

    <script src='https://cdnjs.cloudflare.com/ajax/libs/classlist/2014.01.31/classList.min.js'></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/iamdustan-smoothscroll/0.4.0/smoothscroll.js'></script>

    The main JavaScript to activate the off-canvas navigation & smooth page transition effects.

    let navigation = {
        // Variables
        $navTrigger: document.querySelector('.nav__trigger'),
        $nav: document.querySelector('.nav'),
        $navItems: document.querySelectorAll('.nav__item a'),
        $main: document.querySelector('.main'),
        transitionEnd: 'webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend',
        isOpeningNav: false,
    
        init() {
            let self = this;
    
            // Reset overflow and height on load
            self.$main.style.overflow = 'auto';
            self.$main.style.height = 'auto';
    
            
            // Handle scroll events
            window.addEventListener('scroll', (e) => {
                if (window.scrollY == 0 && self.isOpeningNav) {
                    self.isOpeningNav = false;
                    
                    // Add a small delay
                    setTimeout(function() {
                        self.openNavigation();                    
                    }, 150);
                }
            });
    
            // Handle .nav__trigger click event
            self.$navTrigger.addEventListener('click', (e) => {
                e.preventDefault();
                
                if (!self.$navTrigger.classList.contains('is-active')) {
                    if (window.scrollY !== 0) {
                        // Scroll to top
                        window.scroll({ top: 0, left: 0, behavior: 'smooth' });
    
                        // Enable opening nav
                        self.isOpeningNav = true;                    
                    } else {
                        self.openNavigation();
                    }
                } else {
                    self.closeNavigation();
                }
            });
                    
            // Handle .nav__item click events
            self.$navItems.forEach((navLink) => {
                navLink.addEventListener('click', function(e) {
                    e.preventDefault();
                    
                    // Remove is-active from all .nav__items
                    self.$navItems.forEach((el) => {
                        el.classList.remove('is-active');
                    });
                    
                    // Ad is-active to clicked .nav__item
                    this.classList.add('is-active');
                    
                    // Transition the page
                    self.transitionPage();
                });
            });
        },
        
        openNavigation() {
            let self = this;
    
            // .nav--trigger active
            self.$navTrigger.classList.add('is-active');
    
            // body froze
            document.body.classList.add('is-froze');
    
            // Remove old inline styles
            if (self.$main.style.removeProperty) {
                self.$main.style.removeProperty('overflow');
                self.$main.style.removeProperty('height');
            } else {
                self.$main.style.removeAttribute('overflow');
                self.$main.style.removeAttribute('height');
            }
    
            // .main active
            self.$main.classList.add('is-active');
        },
        
        closeNavigation() {
            let self = this;
            
            // .nav--trigger inactive
            self.$navTrigger.classList.remove('is-active');
    
            // .main inactive
            self.$main.classList.remove('is-active');
            self.$main.addEventListener('transitionend', (e) => {    
                if (e.propertyName == 'transform' && !self.$navTrigger.classList.contains('is-active')) {
                    // Reset overflow and height
                    self.$main.style.overflow = 'auto';
                    self.$main.style.height = 'auto';
    
                    // body unfroze
                    document.body.classList.remove('is-froze');
                }
            });                    
    
            // no-csstransitions fallback
            if (document.documentElement.classList.contains('no-csstransitions')) {
                // .main inactive
                self.$main.classList.remove('is-active');
    
                // body unfroze
                document.body.classList.remove('is-froze');
            }
        },
        
        transitionPage() {
            let self = this;
            
            // .main transitioning
            self.$main.classList.add('is-transition-out');
            self.$main.addEventListener('transitionend', (e) => {    
                if (e.propertyName == 'clip-path') {
                    if (self.$main.classList.contains('is-transition-in')) {
                        self.$main.classList.remove('is-transition-in');
                        self.$main.classList.remove('is-transition-out');
                        self.closeNavigation();
                    }
    
                    if (self.$main.classList.contains('is-transition-out')) {
                        self.$main.classList.remove('is-transition-out');
                        
                        // Add new content to .main
                        
                        setTimeout(function() {
                            self.$main.classList.add('is-transition-in');
                        }, 500);
                    }
                }
            });
        }
    }
    
    navigation.init();