sidebar that appears upon the initial page load

I'm currently working on implementing a sidebar navigation panel for my website using JavaScript, HTML, and CSS. However, I am facing an issue where the sidebar automatically opens when the page is first loaded, even before clicking on the icon to open it. How can I prevent this automatic opening of the sidebar when the page loads initially? Any assistance would be greatly appreciated! Below are the relevant code snippets...

$(document).ready(function(){
    $(".fa-times").click(function(){
        $(".sidebar_menu").addClass("hide_menu");
        $(".toggle_menu").addClass("opacity_one");    
    });
    $(".toggle_menu").click(function(){
        $(".sidebar_menu").removeClass("hide_menu");
        $(".toggle_menu").removeClass("opacity_one");    
    });
});
/*side navigation bar*/
.toggle_menu{
    cursor:pointer;
    z-index: 1000000;  
    opacity: 0; 
}

.sidebar_menu{
    position: fixed;
    width: 20em;
    margin-left: 0px;
    overflow: hidden;
    height: 100vh;
    max-height: 100vh;
    background-color: rgba(17,17,17,0.9);
    opacity: 0.9;
    transition: all 0.3s ease-in-out;
    left:0px;
}

.fa-times{
    right: 1em;
    top : 1em;
    opacity: 0.7;
    cursor: pointer;
    position: absolute;
    color: #8bea8b;
    transition: all 0.3s ease-in-out;    
}

.fa-times:hover{
    opacity: 1;
}

.hide_menu{
    margin-left: -20em;
}

.opacity_one{
    opacity: 1;
    transition: all 0.3s ease-in-out;        
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en">
<head>
  <title>Forestpin</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="fullpage/jquery.fullPage.css" />
  <link rel="stylesheet" type="text/css" href="theme.css">
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 
  <!-- This following line is optional. Only necessary if you use the option css3:false and you want to use other easing effects rather than "linear", "swing" or "easeInOutCubic". -->
  <script src="fullpage/vendors/jquery.easings.min.js"></script>
 
  <!-- This following line is only necessary in the case of using the option `scrollOverflow:true` -->
  <script type="text/javascript" src="fullpage/vendors/scrolloverflow.min.js"></script>
  <script type="text/javascript" src="fullpage/jquery.fullPage.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="sidemenu.js"></script>

</head>
<body>
  
  <!--top navigation bar-->
  <nav class="navbar navbar-default header navbar-fixed-top">
   <div class="container-fluid">
    <div class="navbar-header">

      <a class="navbar-brand" href="#">
        <img alt="Brand" src="images/logofpin.png" id="logofpin">
      </a>
      <img alt="Logo" src="images/logo2.png" class="navbar-brand toggle_menu" id="logo2">
      <div class="sidebar_menu">
        <i class="fa fa-times"></i>
      </div>
     
    </div>
   </div>
  </nav>

Answer №1

To make your Logo div visible, simply assign the class opacity_one to it, and for the sidebar div use the class hide_menu. Take a look at the revised code below!

$(document).ready(function(){
    $(".fa-times").click(function(){
        $(".sidebar_menu").addClass("hide_menu");
        $(".toggle_menu").addClass("opacity_one");    
    });
    $(".toggle_menu").click(function(){
        $(".sidebar_menu").removeClass("hide_menu");
        $(".toggle_menu").removeClass("opacity_one");    
    });
});
/*side navigation bar*/
.toggle_menu{
    cursor:pointer;
    z-index: 1000000;  
    opacity: 0; 
}

.sidebar_menu{
    position: fixed;
    width: 20em;
    margin-left: 0px;
    overflow: hidden;
    height: 100vh;
    max-height: 100vh;
    background-color: rgba(17,17,17,0.9);
    opacity: 0.9;
    transition: all 0.3s ease-in-out;
    left:0px;
}

.fa-times{
    right: 1em;
    top : 1em;
    opacity: 0.7;
    cursor: pointer;
    position: absolute;
    color: #8bea8b;
    transition: all 0.3s ease-in-out;    
}

.fa-times:hover{
    opacity: 1;
}

.hide_menu{
    margin-left: -20em;
}

.opacity_one{
    opacity: 1;
    transition: all 0.3s ease-in-out;        
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html lang="en">
<head>
  <title>Forestpin</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="fullpage/jquery.fullPage.css" />
  <link rel="stylesheet" type="text/css" href="theme.css">
  <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
 
  <!-- This following line is optional. Only necessary if you use the option css3:false and you want to use other easing effects rather than "linear", "swing" or "easeInOutCubic". -->
  <script src="fullpage/vendors/jquery.easings.min.js"></script>
 
  <!-- This following line is only necessary in the case of using the option `scrollOverflow:true` -->
  <script type="text/javascript" src="fullpage/vendors/scrolloverflow.min.js"></script>
  <script type="text/javascript" src="fullpage/jquery.fullPage.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="sidemenu.js"></script>

</head>
<body>
  
  <!--top navigation bar-->
  <nav class="navbar navbar-default header navbar-fixed-top">
   <div class="container-fluid">
    <div class="navbar-header">

      <a class="navbar-brand" href="#">
        <img alt="Brand" src="images/logofpin.png" id="logofpin">
      </a>
      <img alt="Logo" src="images/logo2.png" class="navbar-brand toggle_menu opacity_one" id="logo2">
      <div class="sidebar_menu hide_menu">
        <i class="fa fa-times"></i>
      </div>
     
    </div>
   </div>
  </nav>

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

Change the color of the first element when hovering over any of its siblings using only CSS

I am looking for a solution using only CSS We have 3 circles here. When I hover over circles with the class name "Mycircle", the circle with the class name "BigCircle" should change to red color HTML <div class="BigCircle"></div> <div cl ...

What is the best way to retrieve JavaScript variable data from a GDownloadUrl callback function?

Recently, I attempted to extract data by crawling a website. The website in question offers real-time information on bicycle stations through Google Maps. GDownloadUrl("/mapAction.do?process=statusMapView", function(data, responseCode) { var jso ...

What is the best way to arrange an array of objects in JavaScript by numerical order and then alphabetically?

Possible Duplicate: Sorting objects in an array by a field value in JavaScript I'm looking to sort an array of objects both numerically (by id) and alphabetically (by name). However, the current method I'm using is not giving me the desired ...

Button Hover Effect: Transition with Style

I am trying to implement a one-second transition from the default color scheme to the hover color for a Button element in Material UI. I am using the transitions.create(props, options) method as described in this article: https://medium.com/@octaviocoria/c ...

Tips for customizing the appearance of a redux-tooltip

After implementing the redux-tooltip from this GitHub repository, I wanted to customize its styling to better align with my application's design. However, I realized that the Tooltip-Component's divs do not have any identifiers or class names, ma ...

Retrieving the checkbox value from a dropdown selection

I'm stuck and feeling lost here - I must be missing something obvious. Any help will be greatly appreciated! (I am a beginner in html and javascript) I have created a dropdown menu with an unordered list of items populated from JSON data. Here is the ...

Clicking the submit button in JavaScript will trigger a request to the Spring MVC backend,

When I use the following code, it gives me an object response: @RequestMapping(value = "/NewLogin",method = RequestMethod.POST) public @ResponseBody Token getAllBooks( Token token = new Token(); token.setValue(encryptedMessage); return toke ...

What is the best way to synchronize HTML5 audio playback on different browsers?

When working with audio files in different browsers like Chrome, Firefox, and Safari, I noticed that they seem to start at slightly different timestamps. This discrepancy becomes more pronounced as the audio progresses, with a gap of around 5 seconds after ...

Determine the HTTP status code for a request using Vue.js and Ajax

I need to retrieve the HTTP status code after submitting a form (using the form submission function): return fetch(serviceUrl + 'Collect', { method: "POST", headers: new Headers({ "Content-Type": "application/json", Authoriza ...

Is it possible to create an <h1> heading that can be clicked like a button and actually do something when clicked?

I am currently designing a web page that includes <div class="cane-wrap"> <h1 class="mc">christmas tic tac toe</h1> </div> located at the top center of the webpage, with autoplay running in the backgroun ...

Troubleshooting: AngularJS fails to refresh UI when using SignalR

When I attempt to incorporate this angularjs code into a signalR function, the UI does not update. Even using $scope.$apply() does not trigger a digest. This is the code snippet: var notificationHub = $.connection.progressNotificationHub; notificationHub. ...

Display function not functioning properly following AJAX request

I'm working on a functionality where I want to initially hide a table when the page loads, and then display it with the results when a form is submitted using Ajax. The issue I'm facing is that the code refreshes the page and sets the table back ...

Ways to prevent a div from loading an HTML page

When an external button is clicked, the remove() function on id main is triggered. The issue arises when a user quickly clicks on btn1 and then presses the external button, causing the removal to occur before the event handler for btn1. This results in the ...

Issues with comparing dates

I'm attempting to compare two different dates: Start Date Thursday, October 29th, 2015 at 6:00 PM GMT End Date Friday, October 30th, 2015 at 12:00 AM GMT Simply put, if(end > start) { alert('It works'); } else { alert(&apo ...

Sorting through items based on several URL parameters

In an effort to be concise yet clear, I am working on an ecommerce website using Next.js and Shopify. This site features products that need to be filterable based on certain attributes. I retrieve products from the Shopify API, each with its own Product Ty ...

Using Ruby variable as a parameter in JavaScript

Is there a way to include a ruby variable as a parameter in a JavaScript function for a Rails checkbox? Here is an example of what I'm trying to do: <%= check_box_tag 'Sugestão', prato.id , prato.sugestao,:class => prato.categoria_pr ...

How to Keep Images Within Table Borders From Overlapping?

I am in the process of experimenting with creating a newsletter and have developed a template. I am very new to design and have created a table of album releases that is not fitting within the border I established. How can I resolve this issue? The code s ...

Locate a div element based on its inner text and then apply a specific

I am looking to target a specific div based on its inner text, and then add a class to it. How can I achieve this? For example, consider the following input: <div>First</div> <div>Second</div> <div>Third</div> The desi ...

Align the OutputText centrally within the Div

I am having trouble centering the output from my PHP code. The output is just words that form a sentence, but no matter what I try, I can't seem to get it centered properly. Each PHP function simply echoes out a word like 'banana' as a norma ...

How come the h2::after element is positioned directly beneath the main h2 element, and with a margin-bottom?

I'm puzzled as to why the margin-bottom property in the main h2 element isn't affecting its "::after" element. Both are defined as block elements, so one margin should provide enough space between them. Even though the "h2::after" element has 0 m ...