Struggling with determining the perfect transition speed for the sidemenu display

I'm a newcomer to web development and facing an issue with setting the transition speed for opening and closing this side menu. Despite adding transitions in the CSS and specifying duration in the Javascript, the menu continues to open instantly. I did my research before reaching out here, but none of the solutions seemed to work. Any help from you all would be greatly appreciated.

function openNav() {
    document.getElementById("mySidepanel").style.width = "250px";
document.getElementById("mySidepanel").style.transitionDuration = "0.5s";
    document.getElementById("mySidepanel").style.display = "block";
    document.getElementById("openbtn").style.display = 'none';
  }
  
function closeNav() {
    document.getElementById("mySidepanel").style.width = "0";
document.getElementById("mySidepanel").style.transitionDuration = "0.5s";
    document.getElementById("mySidepanel").style.display = "none";
    document.getElementById("openbtn").style.display = "inline-block";
  }
/** Navigation Bar **/

.sidepanel {
  width: 0;
  position: fixed;
  z-index: 1;
  height: 100%;
  top: 0;
  right: 0;
  background-color: rgba(17, 17, 17, 0.425);
  overflow-x: hidden;
  padding-top: 60px;
  transition: all 0.5s ease-in-out;
}

.sidepanel a {
  padding: 8px 8px 8px 32px;
  text-decoration: none;
  font-size: 25px;
  font-family: "lato", sans-serif;
  color: #818181;
  display: block;
}

.sidepanel a:hover {
  color: #f1f1f1;
}

.sidepanel #closebtn {
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 36px;
  margin-left: 50px;
}

#openbtn {
  font-size: 30px;
  cursor: pointer;
  background: -webkit-linear-gradient(white, #38495a);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 10px 15px;
  border: none;
  float: right;
}

#openbtn:hover {
  background: -webkit-linear-gradient(#748df0c9, #324dbbc9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

a:hover .fas {
  color: #3e5ddac9;
  text-shadow: 0 0 5px #3e5ddac9;
}
a:hover .far {
  color: #3e5ddac9;
  text-shadow: 0 0 5px #3e5ddac9;
}
<div id="mySidepanel" class="sidepanel" style="display: none;">
   <a href="javascript:void(0)" id="closebtn" onclick="closeNav()">×</a>
   <a href="/"><i class="fas fa-home"></i></span> Home</a>
   <a href="emojis.html"><i class="far fa-laugh-beam"></i> Emojis</a>
</div>
  
<button id="openbtn" onclick="openNav()">☰</button>

The JavaScript is responsible for hiding and showing the open button when the sidebar is visible. I attempted setting a transitionDuration within it, but unfortunately, that also did not yield the desired results.

Answer №1

Transitions cannot be applied to the display property, but since you are already utilizing width, stick to that for smooth functionality. There's no necessity to alter transition effects using Javascript as they are already specified in your CSS.

function openNav() {
    document.getElementById("mySidepanel").style.width = "250px";
    document.getElementById("openbtn").style.top = '-50px';
  }
  
function closeNav() {
    document.getElementById("mySidepanel").style.width = "0";

    document.getElementById("openbtn").style.top = '10px';
  }
/** Navigation Bar **/

.sidepanel {
  width: 0;
  position: fixed;
  z-index: 1;
  height: 100%;
  top: 0;
  right: 0;
  background-color: rgba(17, 17, 17, 0.425);
  overflow-x: hidden;
  padding-top: 60px;
  transition: all 0.5s ease-in-out;
}

/* Remaining CSS code is unchanged */

Edit: The position has been updated to fixed and the button has been adjusted vertically.

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

What is the best way to transfer variables between HTML and PHP?

Greetings! I have a quick query: What is the best practice for transferring variables while developing on your website? - get method, post method, session, cookies, hidden fields, etc. ...

Unexpected display issue with Bootstrap-vue navbar component

I am currently working with bootstrap-vue and trying to implement a navbar component within my application. I followed the first example provided in the documentation at this link. All the necessary dependencies are installed as per the bootstrap-vue instr ...

Issue with AngularJS factory $http.get request receiving HTML files as response

Could someone please explain why I keep receiving an HTML file as a return from my Angular factory? This is the route on my backend: function ensureAuthenticated(req, res, next) { if (!req.headers.authorization) { return res.status(401).send({ mess ...

Retrieving the total count of data entries from the JSON server endpoint

Working on a practice application with the JSON server serving as the backend, I have a question. Is there a way to determine the total number of records at an endpoint without actually loading all the records? For example, if my db.json file contains da ...

The issue of a malfunctioning Customized Bootstrap Carousel when used with flex and gap is causing

I have created a unique bootstrap carousel where instead of displaying one div, I showcase three (one in the middle and half of each on the sides). The issue arises when I add borders to my divs and attempt to create spacing between them using display: fle ...

`How can you generate navigation paths using the ngRoute module?`

I am currently working on creating a basic navigation system like the one illustrated below: html: <html ng-app="myapp"> <body> <ul> <li><a href="pages/sub1">sub1</a></li> <li><a href="pages/ ...

updating the HTML DOM elements using JavaScript is not yielding any response

One way that I am trying to change the background of a div is by using a function. Below is an example of the html code I am working with: $scope.Background = 'img/seg5en.png'; document.getElementById("Bstyle").style.background = "url("+$scope.B ...

Remove an owl carousel using Laravel, Vue.js, and Axios

I've implemented a sleek slider on my website to showcase images with accompanying text to visitors. The slider utilizes owl carousel within a vue component and is functioning properly. Now, I'm attempting to add a delete button so that users who ...

Why isn't jQuery working properly for showing/hiding elements?

I am attempting to create a functionality where the string remove field can be toggled to show or hide using a single button, depending on its current state. Initially, it should be hidden (using the hidden HTML attribute), and upon clicking the button, it ...

The animated image gracefully glides down the webpage accompanied by an h3

How can I align an image and h3 tag side by side without the image sliding down? <img src="..." alt="..." /><h3>Shopping Cart</h3> I need them to be next to each other but the image keeps moving down. Any suggestions on how to fix this? ...

I am attempting to rebuild Vuex's Getting Started example by utilizing multiple components, yet I am struggling to understand how to call root methods from within these components

The project I'm working on can be found here. It is a simple one, but for the purpose of learning, I divided it into index and four js files (parent, child, root, and store). My challenge lies in figuring out how to call the increment and decrement ro ...

Is Javascript the best choice for managing multiple instances of similar HTML code?

I am currently facing the challenge of dealing with a lengthy HTML page consisting of around 300 lines of code. The majority of the code involves repetitive forms, each identical except for the ID (which varies by number). Is it considered appropriate or ...

Is it better to define the SVG `viewbox` once in a `symbol`, or each time an SVG is `used`?

Based on my research, some tutorials suggest that when inserting an SVG <symbol> with <use>, the viewBox property only needs to be defined once - in the <symbol> tag. While this method seems to work fine, it results in the contents of th ...

Modify the text color of the sliderInput element within a Shiny application

I am attempting to change the font color of the values (1,2,3,...10) in the sliderInput() from black to white, but I am encountering difficulties. How can I connect the slider with the CSS file to achieve this? ui <- fluidPage( tags$style(type = &quo ...

Having trouble with the unresponsive sticky top-bar feature in Zurb Foundation 5?

According to the information provided on this website, it is recommended to enclose the top-bar navigation within a div element that has both the class "contain-to-grid" and "sticky". However, I have noticed that while the "contain-to-grid" class exists in ...

Loading HTML content in Electron using the renderer process JS

During the development phase, I found that the jquery load method for loading HTML views in Electron was functioning smoothly: app.appContainer.load('html/homePage/homePage.html', () => { app.addListenerToHomePage(false) }); I have individua ...

Having trouble connecting with Node.js and Express; encountering ERR_CONNECTION_REFUSED

I tried following this basic tutorial: After generating the files as instructed, I ran through all the steps but encountered an issue. Regardless of the browser I used, I kept getting "Unable to connect" in Firefox and "This webpage is not available ... E ...

Mastering the syntax of Babel in Node.js

Hey there! I've encountered a syntax issue while migrating to babel. The problem lies in importing an unnamed module. In traditional Node.js default import, it's possible to import without specifying the module name and passing in the app. Howeve ...

Tips for eliminating the gap separating the authentication design from the additional elements within the Laravel, Vue, and Inertia framework

I'm currently working with Laravel and Vue using Inertia. When I log into the system, the authentication layout creates a space at the top of the page. How can I resolve this issue? Here is an image highlighting the space I need to remove, marked wit ...

Replace Jade script with block override

Having trouble overriding a Jade script. tag, nothing seems to work. Here is the code snippet: Layout.jade block foot footer.container#footer .row .twelve.columns All rights reserved. &copy; 2015 Pet Feeder block scripts ...