Double Off-Canvas sidebars found on a single page

I am a beginner with HTML, CSS, JS, and Bootstrap and looking for guidance on how to bring my idea to life.

My concept involves creating a webpage with two Off-Canvas Sidebars:

  • First Sidebar located on the left side that is visible by default upon page load.
  • Second Sidebar positioned on the right side that is hidden by default when the page loads.
  • A close button will be placed on the left Sidebar that, once clicked, will hide it while simultaneously revealing the right Sidebar.
  • Additionally, there will be another close button on the right Sidebar allowing users to close it and display the left Sidebar again.

If anyone could provide assistance or guidance, I would greatly appreciate it.

Thank you for taking the time to read this.

Answer №1

There are numerous ways and options available to create something according to your preferences.

One potential solution could look like the following:

 document.getElementById('sidebar-left').addEventListener('click', function () {
        this.classList.remove('open');
        document.getElementById('sidebar-right').classList.add('open');
});
    
document.getElementById('sidebar-right').addEventListener('click', function () {
        this.classList.remove('open');
        document.getElementById('sidebar-left').classList.add('open');
});
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.page {
  position: relative;
}

.sidebar {
  height: 100vh;
  width: 400px;
  top: 0;
  position: absolute;
  display: none;
}

.sidebar.open {
  display: block;
}

.sidebar.left {
  left: 0;
  background-color: orange;
}

.sidebar.right {
  right: 0;
  background-color: red;
}

.close {
  padding: 10px;
  background-color: yellow;
  position: absolute;
  right: 0;
  top: 0;
  cursor: pointer;
}
<div class="page">
  <div class="left sidebar open" id="sidebar-left">
    <div class="close">close sidebar</div>
    Left Sidebar
  </div>

  <div class="right sidebar" id="sidebar-right">
    <div class="close">close sidebar</div>
    Right Sidebar</div>
</div>

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 Twig path to pass Ajax URL parameter

I'm facing an issue in my Twig view when passing parameters in the AJAX URL path. Since Twig is executed before JavaScript, it doesn't recognize the input value passed as a parameter. Is there a way to solve this without passing the param in data ...

extract element from a string with the help of jquery

When using AJAX to request HTML from a page, the process involves sending a request like this: function getHTML() { //set ajax call var options = { url: '/Controller', type: 'GET', d ...

The contents of my div extend beyond the border-radius

Here is the issue I'm facing: My challenge involves having an <h1> nested inside a <div>. However, when I apply a border-radius to the <div>, the <h1> appears outside of the div. Below is the code snippet: <div class="test ...

What is the reason that certain functionalities do not work on an element that has two CSS classes assigned to it

I have a unique situation with two input elements and a button: <input class="close-acc-usr opt-in" type="text" name="closeAccUsr" /> <input class="close-acc-pin opt-in" type="number" name="cl ...

Is jQuery(document) loaded on 'focus'?

Whenever a user clicks on an input, I intend to activate a method. The code I currently have is: jQuery(document).on('focus click', function(e){ console.log("focused on " + $(e.target).attr('id')); }); However, when I focus on ...

What strategies can be employed to mitigate the activation of the losing arm in a Promise.race?

My current task involves sending the same query to multiple identical endpoints (about five) across various Kubernetes clusters. The goal is to aggregate the results without any delays and report failures to the user while continuing with the process seaml ...

Ways to enlarge the diameter of the inner circle

I've implemented some CSS with JQuery, as seen in this JSFiddle. However, I'm having trouble increasing the width and height of the green circle to be slightly larger than the gray circle (referred to as the main circle) which is positioned at a ...

Display iframe as the initial content upon loading

Seeking solutions for loading an iframe using jQuery or Ajax and outputting the content to the page once it has been loaded. The challenge lies in loading an external page that may be slow or fail to load altogether, leading to undesired blank spaces on th ...

Error encountered in Angular after consolidating JavaScript files into a single file: [$injector:modulerr]

After developing an Angular application, everything seemed to be functioning well when I included the controllers.js, routes.js, directives.js files separately in index.html. However, upon attempting to combine these files into a single js file using gul ...

Issue with the table not being displayed when any of the submitted fields are left empty

After submitting the first field, I receive the second value, and after submitting the second field, I get the third value. I have a group of three fields that are interconnected. <?php $courtname=''; if(!empty($_POST['court_ ...

What steps can I take to ensure that when the user clicks the logout button, they are redirected to the home component?

Struggling to find a way to direct the user back to the Home component after logging out. The API functionality has been tested and is working properly. I'm unsure how to properly implement the logout method in the current context to allow for succes ...

Is Vue js converting nested objects into strings before returning them?

There is an object in my code var user = { name:"test", number:"9666-0503", details:{ test:"cannot_access_this", second_field:"nope_no_go" } } A call to a Vue JS action is being made [TYPES.FETCH_USER]({ ...

Building an Angular 4 app featuring a customized default landing page and URL parameters functionality

I am in the process of developing a web portal that will be embedded within an iFrame. Below is the code snippet I am using to set up the portal: Routes Configuration const routes: Routes = [ { path: '', redirectTo: '/dash ...

I'm having trouble getting jquery css to function properly in my situation

I am trying to implement a fallback for the use of calc() in my CSS using jQuery CSS: width: calc(100% - 90px); However, when I tried running the code below, it seems like the second css() function is not executing. I suspect that there might be an issu ...

What is the best method for implementing page transitions between components in NextJS?

My goal is to create a form that smoothly slides to the right, similar to the one seen on DigitalOcean's website when you click "Sign up using email" here: . While the transition itself is relatively simple, I noticed that DigitalOcean uses 2 separat ...

Setting the initial viewer position in Panolens: A step-by-step guide

I've been working on setting the initial viewer position for panolens.js for a while now. Here's how the set-up looks: const panoPhoto1 = 'https://conceptcityiasi.ro/assets/images/tours/tip1/apartamente-noi-de-vanzare-iasi-dacia-1_camera-ti ...

directive behaves unexpectedly in bootstrap grid

I'm a new AngularJS user:). Having an issue with my directive that controls popovers for icons. It's functioning properly in one location but malfunctioning in another (blinking and causing the popup to shift down and cover the icon). HTML temp ...

The float right attribute doesn't stay contained within the box; instead, it drifts outside the box

I've been struggling to keep this box fixed at the top of the browser, but I'm facing an issue with the positioning on the right side. I can't seem to figure out how to solve it, so I'm reaching out for some help. #StickyBar #RightSide ...

attempting to retrieve a specific nested value using square brackets

I am attempting to track the position of an object associated with a particular row. Ultimately, I require a comprehensive object that includes both the row and the position of a "com" within that row. Below is my code snippet: (g represents a global objec ...

My functional Chrome web-audio app built with React works seamlessly, but when I try running it in Firefox, I encounter an issue where variables are being

The functionality of this app is smooth in Chrome, but encounters issues in Firefox where certain global variables are showing up as undefined. The reason behind this error and how to resolve it is currently unclear to me. In Chrome, pressing the play but ...