Adaptive Navigation using jquery

My jquery code is not working as I want it to. When I click on "openmenu", I would like "closemenu" to move to left: 50% instead of left: 85%

$("#openMenu").click(function(){
    $("#closeMenu").animate({left:"50%"}); 

rather than

$("#closeMenu").animate({left:"85%"});

Code:

$(document).ready(function(){
  $("#openMenu").click(function(){
    $("#main") .fadeIn(200);
    $("#openMenu").animate({left:"-100%"});
    $("#closeMenu").animate({left:"85%"});
    $(".menu").animate({left:"-1%"},10);
  });

  $("#closeMenu").click(function(){
    $("#main") .fadeOut(200);
    $("#openMenu").animate({left:"3%"});
    $("#closeMenu").animate({left:"100%"});
    $(".menu").animate({left:"-50%"},10);
  });
});
#menuSection{
  height: 100%;
  width: 50%;
  background-color: #e78d3a;
  position: absolute;
  left: 50%;
  background-image: url("../images/background_secondary-home.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
}
  
#menuSection ul{
  list-style: none;
  margin: 0px;
  padding:0px;
  position: absolute;
  top: 30%;
  left: -1%;
}


#menuSection ul li{
  height: 100px;
  width: 350px;
  font-family:'Poppins', sans-serif;
  font-size: 60px;
  line-height: 100px;
  cursor: pointer;
  font-weight: 600;
}


.menu{
  height: 100px;
  width: 0px;
  background-color: #ff931e;
  display: flex;
  position: absolute;
  left: -50%;
  cursor: pointer;
  pointer-events: none;
  transition: all .5s;
}

#menuSection ul li:hover .menu{
  width: 350px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Pulse Menu -->
<div  class="pulse" id="openMenu">
    <img class="img-responsive icon-menu_open" src="images/icon-menu_open.svg">
</div>
<!--/Pulse Menu -->

<!-- Menu -->
<div id="closeMenu">
    <i class="fa fa-times icon-menu" style="font-size: 25px;color:rgb(238, 238, 238);position: absolute;top: 30%;left: 100%;"></i>
</div>

I am new to coding and I would like to understand the role of jquery in this scenario.

Answer №1

Your jQuery code contains a crucial line on line 5:

$("#closeMenu").animate({left:"85%"});

I recommend updating it to:

$("#closeMenu").animate({left:"50%"});

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

Adjust the size of the text within the div element as needed

Here is my code on jsFiddle where I am dynamically changing the text font to fit in the div. Everything is working perfectly fine. Currently, the text is within a span element, but I would like to remove the span and have the same functionality. However, w ...

A mistake was found in the HTML code labeled as "enhance-security-request."

The Content Security Policy 'upgrade-insecure-requests' was included through a meta tag that is not allowed outside the document's head. Therefore, the policy has been disregarded. I encountered this issue when trying to add Bootstrap in Bl ...

Ways to extract information from JSON files

Currently, I am working on a script to extract viewer count and follower count data from Twitch. While I have successfully retrieved the viewer count information, I am encountering issues with extracting the follower count. The essential information can be ...

Conforming to HTML5 standards with ASP.Net DataList

I am currently working on updating my ASP.Net 4.0 website to comply as closely as possible with HTML5 specifications. One issue I have encountered is that whenever I use a DataList, it automatically adds the attribute cellspacing="0". I have tried various ...

CSS popup experiencing issues due to Iframe integration

As someone who is relatively new to web development and completely self-taught, I've encountered a challenge with an iframe on my page. I have a CSS and JavaScript popup that is triggered by jQuery. The desired behavior is that when a link is clicked, ...

How can the background color of a DIV be altered based on the values of an array's minimum

Basically, I am fetching values from an array using AJAX. The background color will change from green to red based on the "aht_value". Currently, the colors are displaying correctly because I hardcoded the values in the calculation below. However, I want t ...

Tips for transferring a double value from HTML to PHP

I need assistance in transferring a Double value (for example, 10.9) from an HTML file to PHP. Below is the HTML code I'm working with: <form action="AddProduct.php" method="POST" target="_self"> <table> ...

How do I specify filter selectors for events passed as an object in JQuery's on() method?

I've been pondering about the second syntax of JQuery's on() method where events are passed as an object: services.on({ 'mouseenter': function(e){ console.log('enter', e.target); }, 'mouseleave': function ...

Retrieve input field values using the jQuery Taggd plugin in edit mode

Incorporating the jQuery taggd plugin has been smooth sailing so far. I made a few tweaks, specifically to use it in edit mode. In this edit mode, when a user inputs a value in the textbox, the plugin checks whether it is a URL or a string. If it's a ...

Calculating the time difference in days, hours, minutes, and seconds between two UNIX timestamps

I have a special occasion coming up, and the date and time for this event are stored in a Unix timestamp format. Instead of relying on a plugin like modern.js, I am trying to figure out the time difference between today's date and the event date usin ...

Incorporate real-time options into a select menu using ajax

I'm attempting to dynamically update options within a dropdown using PHP, jQuery, and AJAX. Firstly, I make an AJAX call when the initial control (taglist) undergoes a change: $('#taglist').change(function(){ $.post('../includes/ ...

Slick Slider isn't compatible with Bootstrap Tab functionality

I'm having an issue with using slick slider within a Bootstrap tab menu. The first tab displays the slick slider correctly, but when I switch to the second tab, only one image is shown. How can I resolve this problem? <!DOCTYPE html> <html ...

Adding a Video as a Background Button Using HTML and CSS

My attempt to utilize background-image in CSS for the button background was unsuccessful as it only supports images, not videos. Is there a way to set a video as the background of a button? My goal is to create a button with a continuously looped muted v ...

What are the best practices for avoiding text wrapping around a DIV?

I have scoured this site extensively, searching for a solution to my problem. What I thought was a simple issue has left me frustrated after hours of trying to figure it out on my own. So, I've finally admitted defeat and turned to seek help... Here& ...

Discover the position of a chosen element using jQuery

Greetings! I am looking to retrieve the index of the column of a selected item in a table in order to create a color indicator in the header of the table. As the mouse moves, I want the header of the table containing the element to change color. Below is ...

Enhance the appearance of Bootstrap forms with custom styles

After customizing a selection form in Bootstrap to mimic a specific image, I have successfully added the necessary styles. If you wish to see the html and css used to achieve this design, please refer to the link below: https://i.sstatic.net/b67Yf.png HT ...

What is the best way to customize the appearance of a mat-checkbox in Angular using Angular Material?

Is there a way to customize the appearance of a mat-checkbox that actually works? I've tried various solutions without success. I attempted to disable view encapsulation and use classes like mdc-checkbox__background, but nothing changed. Even applyin ...

CSS - Adding a Distinctive "Line" to a Navigation Bar

I am attempting to design a unique navbar layout with two "lines". The first line should consist of several links, while the second line would include an HTML select field with a submit button. The following code will generate the desired navbar visual ou ...

ReactJS: Want to update card design by utilizing the onClick event handler

Currently, I am aware that there will be a need to refactor this code later on to separate things into their own components. However, due to time constraints, I have to wire this up as is at the moment. To achieve this, I utilized array.map() to create car ...

What is the best way to initiate an onload event from a script embedded within a jquery plugin?

Currently, I am in the process of developing a jQuery plugin. One issue that I have encountered involves a script tag being dynamically added for LivePerson.com. The script is supposed to trigger an onLoad function specified in the configuration. However, ...