Pulling a Bootstrap 3 Navbar from the side

I was in the process of developing a navigation bar for my Bootstrap website when I had an idea to make it more visually appealing by having it slide out from the left side of the page. In order to achieve this effect, I decided to proceed with the following steps:

  1. The user initiates the action by clicking on the .navbar-toggle element.
  2. Subsequently, the navigation bar smoothly slides out from the left side, covering approximately 3/4th of the entire page. This design is inspired by the layout seen on the renowned Airbnb website:

https://i.sstatic.net/81EuC.png

I am curious as to how I can implement this feature. My hypothesis is that the desired functionality can be achieved through the utilization of the slideIn() jQuery function, which I also plan to incorporate into the project. It is important to note that this particular navigation bar will only be visible on mobile devices. Below you can find the code snippet that I have currently worked on:

http://codepen.io/aravind-forever/pen/ozGkWZ

Answer №1

Hey, based on your requirements for a 3/4 sidebar, it means that if the whole page width is 100%, you want your sidebar to occupy 75% of that page. Check out the following demo link for a fiddle example that may help you achieve this: sidebar Fiddle

Answer №2

If you're looking to achieve a specific functionality in your project, consider adding some CSS rules and a touch of jQuery to your code.

For reference, here is a link to a CodePen that I've put together which may provide some guidance:)

http://codepen.io/shashanksmaty/pen/pEWPaP

HTML:

<nav class="navbar navbar-default navbar-fixed-top">
 <div class="container-fluid">
 <div class="navbar-header">
  <button type="button" class="navbar-toggle">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <a class="navbar-brand" href="#">BrandName</a>
</div>
<div class="container-nav">
  <div class="nav-mask"></div>
  <div class="nav-list">
    <div class="nav-list-wrap">
      <ul class="list-unstyle">
        <li><strong>Home</strong></li>
        <li><strong>Downloads</strong></li>
        <li><strong>Contacts</strong></li>
        <li><strong>About Us</strong></li>
      </ul>
    </div>
  </div>
</div>

CSS:

.container-nav{
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 2000;
  visibility: hidden;
}

.nav-mask{
  position: absolute;
  height: 100%;
  width: 100%;
  background-color: #000;
  opacity: 0;
}

.nav-list {
  position: absolute;
  width: 285px;
  height: 100%;
  z-index: 2001;
  background: #000;
  color: #FFF;
  right: -285px;
}

.nav-list-wrap {
  padding: 30px 10px;
}

.list-unstyle {
  list-style-type: none;
}

.list-unstyle li {
  padding: 5px;
  font-size: 20px;
  cursor: pointer;
}

.list-unstyle li:hover {
   text-decoration: underline;
}

jQuery:

$('.navbar-toggle').on('click', function(){
  $('.container-nav').css("visibility", "visible");
  $('.nav-mask').css({
    "opacity": "0.6",
    "-webkit-transition": "opacity 0.5s ease-in",
    "transition": "opacity 0.5s ease-in"
  });
  $('.nav-list').css({
    "right": "0px",
    "-webkit-transition": "right 0.5s cubic-bezier(.17,.67,.61,.98)",
    "transition": "right 0.5s cubic-bezier(.17,.67,.61,.98)"
  });
});

$('.nav-mask').on('click', function(){
  $('.container-nav').css("visibility", "hidden");
  $('.nav-mask').css({
    "opacity": "0",
    "-webkit-transition": "opacity 0.5s ease-in",
    "transition": "opacity 0.5s ease-in"
  });
  $('.nav-list').css({
    "right": "-285px",
    "-webkit-transition": "right 0.5s cubic-bezier(.17,.67,.61,.98)",
    "transition": "right 0.5s cubic-bezier(.17,.67,.61,.98)"
  });
});

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

Remove the part of the string that comes before a specific string and return the remaining

Here is a unique and straight-forward question that I couldn't find anything similar to. The following snippet shows HTML code stored in a string: $one = "<html> <head> something> </head> <body> </body> </html> ...

Is there a way to selectively load only the <head> content from AJAX data and update the current <head> element?

While attempting to retrieve the <head> content of data using AJAX and replace it with the current one, I am encountering errors and the code at the bottom is not functioning as expected. $('head').html($(data).find('head:first') ...

Utilize CodeIgniter to load a distinct view that smoothly slides into the current view

As I delve into a PHP test project using CodeIgniter, I have opted for a parallax template which comes with a separate HTML file that slides open upon clicking a link. My current challenge lies in figuring out how to load this separate view within the mai ...

Disabling the submit button after submitting the form results in the page failing to load

I am encountering an issue with my HTML form that submits to another page via POST. After the form validates, I attempt to disable or hide the submit button to prevent double submission and inform the user that the next page may take some time to load. He ...

The scroll() function in jQuery does not bubble up

Recently, I encountered an issue with a Wordpress plugin that displays popups on scroll. The code I currently have is as follows: jQuery(window).scroll(function(){ //display popup }); The problem arises with a particular website that has specific CSS ...

Tips for implementing validation on dynamically generated fields

Currently, I am implementing JavaScript validation methods and rules for my form which is functioning properly. However, I have a feature where users can add multiple phone numbers by clicking on an "Add More" button. The challenge I am facing is how to va ...

The perplexing phenomena of Ajax jQuery errors

Hey there! I'm having a bit of trouble with ajax jquery and could use some guidance. $.ajax({ type:"get", url:"www.google.com", success: function(html) { alert("success"); }, error : function(request,status,error) { alert(st ...

Issues with Bootstrap Table Column Widths not Adjusting Properly

I am facing an issue with my Bootstrap 4 table where the fixed column widths specified in the header row are not being respected when the table is rendered. The Time column, for example, should only be 5% of the width but it is taking up more space than ex ...

How can jQuery be used to adjust the width and height of an iframe?

After researching a solution on a website, I attempted to implement it but encountered issues. It seems like there may be another script dictating the styling, so I need to add some code directly to the page to override it. This is what I tried: <scri ...

What steps should I take to modify my navigation menu to display 'Logout' once a user is logged in?

I'm currently working on a small project to create a basic website and I am struggling with implementing a feature in PHP that changes the menu navbar to "Logout" once the user has successfully signed in. Below, you can find the navbar code as well a ...

How to horizontally align Yii's CHtml radioButtonList using CSS

I am currently using yii framework for my development and I have encountered an issue. While writing CSS, I was able to align my <input tags in HTML properly. However, when I applied the same CSS to yii, the alignment got messed up. Can anyone offer som ...

Unsure about the erratic actions of my JavaScript code

My current challenge involves a function that aims to return a global variable as a String object, containing the contents of a local text file. As it stands, this function is returning an empty String. function fetchWords() { var fileRequest = new XM ...

Display Tooltip for Angular (ng2-tooltip-directive) exclusively when the value is defined

I have integrated the Tooltip for Angular (ng2-tooltip-directive) into my application to display tooltips. Given the code below, how can I ensure that tooltips are hidden whenever the title is undefined? //HTML <div tooltip="{{title}}"></div> ...

Switching Flexbox CSS from a column layout to a row orientation

When the viewport width reaches 750px, I want to use flexbox to change the layout of my information from one column to four rows: * { box-sizing: border-box; } h1, h2, h3, h4, h5, h6 { text-align: center; } section { border: inset #333 thin; p ...

Creating dynamically resizing tab buttons in Ionic 2

Is there a way to create flexible width tabs buttons? For example, these are my normal tabs: https://i.sstatic.net/mXnIG.png I would like the tabs' width to be similar to this image: https://i.sstatic.net/lNgHm.png I attempted to display the full ...

Sending numerous variables through a JSP URL

I am attempting to send multiple values in a JSP page URL to another one. Below is the code I'm using: <form name="QuantityForm" onsubmit="return quantityValidation()" action='<%="basket.jsp?addItem="+product.PID%>' method="post"&g ...

Tips for isolating individual response div IDs in an AJAX request

Seeking assistance to resolve an issue. function initiateRequest(){ var req; if(window.XMLHttpRequest){ //For Firefox, Safari, Opera req = new XMLHttpRequest(); } else if(window.ActiveXObject){ //For IE 5+ req = new ActiveX ...

The iPad1 is having trouble displaying the background image, while the iPad2 is showing it perfectly

I am experiencing issues with the background image on my website not displaying properly on an iPad 1, however it appears fine on an iPad 2. Does anyone have any suggestions or ideas on how to fix this? Thank you in advance. ...

asymmetrical bootstrap grid columns

I am working with the Bootstrap 4 grid system and have a layout with 3 columns. I want the first and third columns to be col-8, and the second column to be col-4, acting as a sidebar that falls between the first and third columns on small screens. However, ...

Is the form data in AngularJS not submitting correctly?

Why is my HTML form data not being submitted using POST method? HTML View Page:- <div class="col-sm-12"> <div class="card-box"> <form class="form-inline" name="addstock" ng-submit="saveStockPurchaseInvoice()"> <h ...