Personalized Navigation Bar Toggle (transitioning from dropdown to sliding from the left)

On larger screens, I would like the navigation/navbar to be positioned at the top. However, on mobile view or when collapsed, I want the toggle button to reveal the navigation menu by sliding from the left side, similar to this example:

(source by David Bushell: )

Many websites and examples use a duplicate of the navigation items in another div that becomes visible when the toggle button is pressed in mobile view. This approach seems redundant to me. While some examples have the menu appearing as a sidebar by default, I prefer having the menu at the top by default and sliding out from the left upon toggling. Despite my extensive research, I couldn't find exactly what I was looking for.

Issue:

I am working on Visual Basic web-form MVC and would like to implement a similar slide-out menu feature to my current project. I'm using the default Bootstrap navigation with dropdown menus triggered by navbar-toggle.

My question is:

Is there a way to modify the default dropdown navbar-toggle menu behavior to slide from the left? I have no idea where to start in terms of changing the jQuery code or other aspects.

(I think we might need to create a new class and apply it when the navbar-toggle icon is clicked, but this is just my speculation)

NOTE: I am not an expert coder, so please explain things at a beginner to intermediate level.

Here is the code snippet:

<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse"
                data-target="#public-menu-navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="pull-left brand" href="#"><img src="~/Images/Logo-Main.png" /></a>
    </div>

    <div class="collapse navbar-collapse" id="public-menu-navbar-collapse">
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#">list 1</a></li>
            <li><a href="#">list 1</a></li>
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    list 3
                    <span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="#">Change Password</a></li>
                </ul>
            </li>
            <li><a href="@Url.Action("Login","Home")">Login</a></li>
        </ul>
    </div>
</div>

This is the whole body code

  <body>
  <div class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#public-menu-navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>

        </div>
        <div class="collapse navbar-collapse" id="public-menu-navbar-collapse" >
            <ul class="nav navbar-nav">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("Contact", "Contact", "Home")</li>
            </ul>
        </div>
    </div>
</div>
<div class="container body-content">
     <div class="container-fluid">
    <div class="row">
        <div class="col-md-4 left_space">
        </div>

        <div class="col-md-8 col-md-offset-4">
            <div class="row">
                @RenderBody()
            </div>
        </div>
    </div>
</div>
    <hr />
    <footer>

    </footer>
</div>
</body>

Looking for answers, suggestions, or guidance...

Answer №1

While exploring options, I came across something that might be of interest to you. Check out this resource from Jasny Bootstrap. It offers an OffCanvas feature that could assist in creating the design you have in mind.

Answer №2

Here's a simple solution. Update the default behavior by changing it from

<button ... data-toggle="collapse" data-target="#public-menu-navbar-collapse">

to

<button ... data-toggle="slide-collapse" data-target="#public-menu-navbar-collapse">

After making this change, you can implement the following script for mobile menu slide effect:

// Slide in the mobile menu from the left
$('[data-toggle="slide-collapse"]').on('click', function() {
    $navMenuCont = $($(this).data('target'));
    $navMenuCont.animate({'width':'toggle'}, 350);
});

Ensure that your navbar has appropriate CSS styling, such as the following example (verify the class name):

.navbar-collapse {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 10000;
    width: 280px; /*adjust as needed, avoid using min-width */
    height: 100%;
}

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

Perform a POST request in JavaScript and handle the response in PHP

Currently, I am in the process of gathering data through a form and executing this JavaScript: fetch('process.php', { method: 'POST', body: formData, }).then(response => alert( response ) ); The execution of process.php hap ...

What causes the sudden disappearance of the returned value from AJAX?

This piece of code is what runs on my server: modify_emp.php <?php echo $_POST[id]; ?> Below is the Javascript code in my HTML page: <script> $(document).ready(function () { var alreadyClicked = false; $('.element').h ...

How to efficiently manage multiple emits in socket.io using long polling

Is there a suitable solution to handle long polling clients in scenarios similar to this? sockets.in("room1").volatile.emit(message); sockets.in("room2").volatile.emit(message); In this case, the client is present in both rooms but receives the message o ...

No data received from AJAX response

I've spent around 8 hours trying to figure this out with no success. Using $.ajax, I am trying to retrieve data from my database through a PHP script. However, it seems like it's not working in this particular case and I have no idea why. The va ...

Creating an HTML form that spans across multiple pages: Tips and tricks

When creating a shopping form that includes items like mugs and tshirts, is it permissible according to website standards to design a form that spans multiple pages? One option could be to add radio buttons for choosing a color directly on the main form ...

What is the best way to create a dynamic string based on a list's contents?

To create a personalized message, I am looking to generate a string based on user input and then loop through a list of first names. For instance: Given a list of first names: let firstnameList = ["Jan", "Mark","Doe"] And a message entered by the user: ...

javascript accessing an external variable inside ajax function

I have implemented dajaxice to fetch a json attribute that I want to make global. However, I am facing an issue where my global variable is always showing up as "undefined": var recent_id; $(function(){ recent_id = Dajaxice.ticker.get_home_timeline(ge ...

How can I conceal the contents of a webpage until the entire page has finished loading before revealing them?

Is there a way to delay displaying my login template until all elements are fully loaded? Currently, when I visit the site, the template appears first followed by fonts and other components. I want to ensure that nothing is shown to the user until the enti ...

Finding the index and value of a specific HTML element with jQuery click event

I'm currently working on creating an Ajax function to delete items from a list using Jquery ajax. Here is the HTML structure: <ul> <li><a class="del"><span style="display:none;">1</span></a></li> <li& ...

Customizing Your JQuery.awesomeCloud.plugin with a Tooltip Functionality using jQuery

Is it possible to integrate a jQuery Tooltip feature when hovering over specific words in a word cloud? I am currently using [jQuery.awesomeCloud.plugin]:https://github.com/indyarmy/jQuery.awesomeCloud.plugin If there is an alternative method to add toolt ...

CodeMirror version 5.62.3 is experiencing some challenges with the scrollbar functionality, editor size, and line wrapping

During my HTML/CSS/JS coding session, I encountered a challenge with CodeMirror version 5.62.3. Specifically, I was striving to make the scrollbar visible in the code editor, using C# as the language mode. However, despite setting the editor's height ...

best practices for creating space between flexbox items

My task involves presenting a continuous scroll list of scheduled jobs using Angular Material. Each item in the list needs to be divided into three columns utilizing flexbox. Despite my efforts, I am struggling with adding space between the columns within ...

Tips for preventing the direct copying and pasting of JavaScript functions

Repeating the process of copying and pasting functions such as loadInitialValue(), loadInitialValue2(), loadInitialValue3(), is quite monotonous. This is the repetitive code snippet that I have been working on (when you click on "Mark as Read," the title o ...

When passing a parameter in a JSP page, it returns a null value

How can I display the name of my image like so? This is a simple post request from demo.jsp to itself. <form method="post" action="demo.jsp"> <input type="hidden" id="sql" name="name" value="sql"/> <input type="image" src="images/icons/ic ...

Validate form for radio group

Hello Experts, I am currently working on developing a form that includes a JavaScript validation function for a radio group. The main objective is to have a division pop up when either "Monday" or "Tuesday" is checked, and no popup when "None" is selected ...

Sorting through various data inputs in one JSON file

I have a JSON file containing an array of objects: obj= [{fname:"abhi",age:5,class:"ten",lanme:"kumar" },{fname:"abhi",age:5,class:"ten",lanme:"kumar" },{fname:"abhi",age:5,class:"t ...

Removing page scrolling in Bootstrap 5: A step-by-step guide

I would like to ensure that only the card-body block is scrollable. Currently, the page does a bit of scrolling when the card-body block overflows (resulting in 2 scroll bars). The lorem text was added as an example of an overflow. The desired outcome is d ...

Using React to display data from a nested JSON object in a table

I am currently working on parsing a JSON object into a table using React. However, I am facing an issue with utilizing the .map() function to create a row for every unique combination of course code, name, transferable_credits, transferable_credits -> i ...

Are you ready to initiate the object using setInterval?

My Sockjs reconnect method is almost fully functional, except for a small error: (function() { // Initialize the socket & handlers var connectToServer = function() { var warbleSocket = new SockJS('http://url.com:5555/warble'); w ...

Tips for connecting to multiple items in an md-select element from within a directive

Looking to develop a straightforward directive that displays either a textbox or dropdown based on whether an array is provided for the model property on the scope. Any value other than explicitly setting false in the directive markup such as multiple="fa ...