Animate the entrance of mobile content as it slides into view while scrolling

I am currently working on a WordPress theme and facing an issue:

When I click the hamburger menu without scrolling down the page, the mobile menu slides in smoothly. However, if I scroll down the page, the mobile menu fails to slide into view (I have to scroll back up to see it).

I've experimented with various solutions like setting overflow-y to scroll, but nothing seems to work! Do you recommend using JavaScript?

Here's the HTML/PHP code snippet:

<nav class="navbar navbar-fixed-top navbar-light">
        <div class="container">    
                <a class="navbar-brand" href="#">
                    <img src="<?php bloginfo('template_directory');?>/img/fullLogo.png" class="fluid-img pull-md-left" id="navLogo">
                </a>

                <div class="hidden-sm-down">
                    <?php 
                    $mobileMenu = array(
                        'sort_column' => 'menu_order',
                        'container' => false,
                        'theme_location' => 'mobile_menu',
                        'menu_class' => 'desktop-nav',
                        'container_id' => 'desktopNavContainer', 
                    );
                    wp_nav_menu( $mobileMenu );
                    ?>
                </div>

                <a>
                    <button type="button" id="hamburger" class="pull-right hidden-md-up">
                        &#9776;
                    </button>
                </a>
        </div>
        </nav>
    <div id="mobileMenu">
        <button type="button" id="mobileMenuCloseButton" class="pull-right">
            &#735;
        </button>
        <div id="mobileNavWrapper">
            <?php 
                $mobileMenu = array(
                    'sort_column' => 'menu_order',
                    'container' => false,
                    'theme_location' => 'mobile_menu',
                    'menu_class' => 'mobile-menu',
                    'container_id' => 'mobileNavContainer', 
                );
                wp_nav_menu( $mobileMenu );
            ?> 
        </div>
    </div>

The CSS styling for navigation components:

/******** NAVIGATION ************/

#mobileMenu{
    display: none;
    position: relative;
    z-index: 10000;
    top: 0;
    background-color: rgba(0,0,0,.95);
    width: 100%;
    font-size: 3em;
    text-align: center;
    overflow-y: scroll;
}

#mobileNavWrapper{
    margin-bottom: 70%;
}

#mobileMenuCloseButton{
    font-size: 2em;
    color: white;
    position: absolute;
    top: -25px;
    right: 9%;
}

Lastly, let's take a look at the JS implementation:

/* ----------- MOBILE MENU APPEAR --------------- */
    $('#hamburger').click(function(){
        console.log('got it');
        $('#mobileMenu').slideDown(400);
    });

    $(window).scroll(function(){
        if ($(window).scrollTop() > 600){
            $('#mobileNav').addClass('menuScrolled');
        } else{
            $('#mobileNav').removeClass('menuScrolled');
        }
                     });

Answer №1

Hey there, check out this quick mock up I put together for a fixed header to show you how the navbar sticks to the top.

Here's the HTML:

<nav class="mobile-header">
      <ul>
        <!-- Keeping this empty for now --> 
      </ul>
      <div class="hamburger">
        <i class="fa fa-bars fa-2x"></i>
      </div>
    </nav>

And here's the CSS:

.mobile-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 75px;
  background-color: rgba(0, 0, 0, 0.8);
}

.hamburger {
  position: absolute;
  top: 20px;
  right: 20px;
}

Check out the code in action here!

Take a look at how it works ^

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using the device's width and height with material-ui

Currently, I am attempting to specify the width and height for only the (Iphone 7 Plus) within my project using withStyles. import { withStyles } from "@material-ui/core"; I have tested the following code: "@media (width: 414px) and (height ...

Unable to render Material Icons on Vue/Quasar web app hosted on Azure

I am facing an issue with my webapp built using Vue and Quasar. I added the necessary icon imports to my quasar-user-options.js file. import '@quasar/extras/material-icons/material-icons.css' import "@quasar/extras/material-icons-outlined/ma ...

Styling with CSS or using tables: What should you choose?

Is there a way to replicate the frame=void functionality in CSS, or will I need to manually add frame=void to each table I create in the future? <table border=1 rules=all frame=void> I attempted to search for a solution online, but unfortunately, m ...

Encountering a Blank Area at the Top of a Printed AngularJS Screen

Currently, I am tackling an issue in AngularJS while working on the Print Invoice Page. The problem I am encountering is a blank space at the top of the printed screen. Check out the image here Below is my code: HTML <div id="invoice" class="compact ...

Text font automatically adjusts size in Chrome on Android

It seems that when a paragraph of text reaches a certain length, Google Chrome on Android decides to resize the text and make it larger (which can cause some interesting results). I've noticed that on my website, about half of the p-tags stick to the ...

Overlapping Bootstrap cards conundrum

Does anyone know how to align Bootstrap cards and make them responsive? I have them centered, but they are overlapping and sticking to the left side. This is for email development with a maximum width of 680px. Any assistance would be greatly appreciated! ...

Positioning images within a relatively positioned div using absolute positioning

I have come across multiple discussions on this topic, but I am still struggling to make the following code snippet function correctly: .container { position: relative; width: 100%; } .left { position: absolute; left: 0px; } .right { positio ...

Scrolling through four limited list items automatically

Hey there! I am currently working on a design project. You can check it out here. I'm trying to replicate a section from another site, which you can see here. <div class="latest-winners-container"> <h3 class="header">Latest Winners< ...

Interrupt the current with an external factor

I am working with a flexbox layout that currently looks like this: https://i.stack.imgur.com/ULHEk.jpg My main question now is whether there is a way to disrupt the flow externally from the flexbox, so that the blocked element can move to the next positi ...

What is the best way to align the menu to the center

Hey there, I'm trying to center a dropdown menu in a 970px wide div. No matter what I do, I can't seem to get it to work correctly. <div id="menuwrapper"> <ul class="menu" id="menu"> <li><a href="#" >Home</ ...

Dynamic Website (Link Relationships / Responsive Design / Content Rendering with CSS and HTML)

Hello everyone! My name is Mauro Cordeiro, and I come from Brazil. I am just diving into the world of coding and have been following various tutorials. Stack Overflow has been an invaluable resource for me in my learning journey! Aside from coding, I am a ...

Twitter-Bootstrap: implementing text underlines for thumbnail captions

While experimenting with Bootstrap, I aimed to create a layout similar to ; a grid featuring bordered panels containing text and images. After some research, I concluded that Bootstrap's Thumbnail component would be the most suitable choice for my pro ...

Utilizing JQuery to ensure that rows have consistent height in two dynamically generated tables

To meet my specific requirements, I am tasked with creating two separate tables that will contain the same number of rows but different data. The first table will display Item Information, while the second table will provide consolidated information about ...

Is there a glitch in Safari's CSS involving max-height?

Currently, I am in the process of developing a popup for a registration form. The CSS rules have been configured accordingly and after testing on various browsers, it has come to my attention that Safari is displaying an additional white space between elem ...

positioning two out of three items in a navigation menu to the right and the remaining one to the left

I am looking to design a navigation bar that spans the full width of the screen, with the logo on the left side serving as a link back to the home page. Additionally, I want to include elements for register/login and cart. The background color should cove ...

Issue with DIV positioning in IE when another DIV is animated downwards

Here's how my page structure looks like: <header> <div class="slide"> <!---- some elements here ---> </div> <nav> <ul> <li id="open"></li> <! --- other parts of the navigation ...

Generate a new style element, establish various classes, and append a class to the element

Is there a more efficient solution available? $("<style>") .attr("type", "text/css") .prependTo("head") .append(".bor {border:2px dotted red} .gto {padding:10px; font-size:medium}"); $("input:text").addClass("bor gto").val("Enter your t ...

Using inline JavaScript to style an element when clicked

Looking for assistance with styling a link. I've connected an external stylesheet to my HTML file, so that part is all set. The goal is to modify the text-decoration when the onclick event occurs. Here's what I currently have: <a class="dopel ...

Struggling to locate the correct path for the CSS file in Express and Handlebars

As part of a student exercise, I am attempting to access an API containing information about presidents and style them using CSS. However, I am facing issues with linking the style.css file. I have tried various methods to change the path and public path ...

Is there a way for me to detect if the user has manipulated the CSS or JavaScript in order to alter the look of my website?

Is there a way to determine if someone is utilizing script or CSS extension tools? For instance, if they have adjusted alignments, applied display: none; to multiple elements, or utilized jQuery's .hasClass to manipulate divs. ...