Is there a way to create a dropdown menu that stretches across the entire page width when the burger menu is hovered over?

Is there a way to create a full-width dropdown menu that appears when the burger icon is clicked, while still maintaining the close function? (The dropdown menu and burger icon should transition smoothly when clicked)

Here are the JavaScript functions for animating the burger menu. The menu transitions on hover and closes when clicked:

 $("#wrapper").hover(function() {
    $(".menu").toggleClass("transition");
  });

$("#wrapper").click(function() {
  $(".transition").toggleClass("close");
});

Below is the CSS code for transitioning the burger menu on hover and applying the closed state:

<style>
.burgerMenu-right {
    font-family: 'Circe Rounded', sans-serif;
    font-weight: 800;
    display: inline;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 8px;
    font-size: 20px;
    color: black;
    float: right;
    position: relative;
  right: 4%;
}

.main-item {
  width: 30px;
  height: 30px;
  position: relative;
  cursor: pointer;
}



.line {
  position: absolute;
  height: 2px;
  width: 100%;
  background: white;
  border-radius: 2px;
  transition: all cubic-bezier(0.25, 0.1, 0.28, 1.54) 0.32s;
  background: black;
}

.line01 {
  top: 33.3%;
  width: 100%;
  left: 0;
}

.line02 {
  top: 66.6%;
  width: 65%;
  right: 0;
}

.menu:hover .line01 {
  width: 65%;
}

.menu:hover .line02 {
  width: 100%;
  top: 66%;
}

.menu.close .line01 {
  transform: rotate(45deg);
  top: 49%;
  width: 100%;
}

.menu.close .line02 {
  transform: rotate(-45deg);
  top: 49%;
  width: 100%;
}


</style>

Lastly, here is the HTML code for implementing the burger menu:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
  <div class="main-item menu">
    <span class="line line01"></span>
    <span class="line line02"></span>
  </div>
</div>

Thank you!

Answer №1

try using the code snippet provided below

$(document).ready(function($) {

$(".menu").click(function(){
  $(this).toggleClass("transition close");
   $(".down-bg").slideToggle();
})
});
.burgerMenu-right {
    font-family: 'Circe Rounded', sans-serif;
    font-weight: 800;
    display: inline;
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 8px;
    font-size: 20px;
    color: black;
    float: right;
    position: relative;
  right: 4%;
}

.main-item {
  width: 30px;
  height: 30px;
  position: relative;
  cursor: pointer;
  z-index: 10
}



.line {
  position: absolute;
  height: 2px;
  width: 100%;
  background: white;
  border-radius: 2px;
  transition: all cubic-bezier(0.25, 0.1, 0.28, 1.54) 0.32s;
  background: black;
}

.line01 {
  top: 33.3%;
  width: 100%;
  left: 0;
}

.line02 {
  top: 66.6%;
  width: 65%;
  right: 0;
}

.menu:hover .line01 {
  width: 65%;
}

.menu:hover .line02 {
  width: 100%;
  top: 66%;
}

.menu.close .line01 {
  transform: rotate(45deg);
  top: 49%;
  width: 100%;
}

.menu.close .line02 {
  transform: rotate(-45deg);
  top: 49%;
  width: 100%;
}
.down-bg{
  background: rgba(0,0,0,0.5);
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="wrapper">
  <div class="main-item menu">
    <span class="line line01"></span>
    <span class="line line02"></span>
  </div>
  <div class="down-bg"></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

Is there a way I can showcase my tags such as "vegan, pasta, etc." using the map feature from Firestore?

Is there a way to display all of my labels like "vegan, pasta, etc." from Firestore using the map function? Currently, I am only able to map out the first object [0]. How can I map out all options instead of just one? Here is an example of what works righ ...

How can I modify cell padding using a media query for a specific screen resolution?

In the desktop view, which is larger than 480px, I need a specific <td> to have a left-padding of 9px. However, once the resolution goes below 480px, this left-padding should increase to 18px. At the moment, my padding definition is specified within ...

Django: The Art of Rejuvenating Pages

Consider the following code snippet which updates the timestamp of a database model whenever it is accessed: def update_timestamp(request): entry = Entry.objects.filter(user=request.user) entry.update(timestamp=timezone.now()) return HttpRespo ...

incapable of modifying the JSON file on the client end

In my JavaScript code, I am attempting to edit a JSON file named "client.json" located on the local system. The file is only modified locally. A form is used to collect new client details, and I aim to append these details as an object to the JSON file. ...

"Troubleshooting: Why isn't my jQuery AJAX POST request successfully sending data to

Here is the jQuery code snippet that I am currently working with: $("#dropbin").droppable( { accept: '#dragme', hoverClass: "drag-enter", drop: function(event) { var noteid = "<?=isset($_POST['noteid']) ? ...

The not:first-child selector targets all elements except for the first one in the sequence

This is a simple js gallery. I am using not:first-child to display only one photo when the page is loaded. However, it does not hide the other photos. You can view the gallery at this link: (please note that some photos are +18). My objective is to hide ...

Showing nested JSON data in ng-repeat

Currently, I'm struggling to understand how to access nested JSON and show it on a page using Angular. For instance, consider the JSON structure below where I want to display connectivity products under portfolio using ng-repeat... { "addons": [ ...

Expanding the size of your Bootstrap 3 input box

https://i.sstatic.net/h7HpX.png Incorporating Bootstrap 3 into a Flask application, I have created a basic layout so far: <div class="container"> <div class="row"> <div class="col-xs-12"> <div class="content"> ...

Transformation of JSON data from Array to Object

I have a JSON data structure that looks like this: { tag: 'new-tag', stream_subjects: [1, 2, 3] } My goal is to transform it into the following format: { tag: 'new-tag', stream_subjects: [ {subject_id: 1}, {subject_id ...

Focus on a specific div element while bypassing its parent

Can I directly target the element with .div-3 class, even if its parent does not have an id or class? <div class="wrapper"> <div> <div> <div class="div-3"> </div> </div> </div> </div> I am aware ...

Tips for utilizing Plunker or JSFiddle to execute Angular2 code

I've been attempting to practice coding programs in Angular 2 using plnkr and jsfiddle. However, every time I try to run them, I encounter issues such as 404 errors or exceptions when I check the developer tools. Can anyone advise on the correct metho ...

Implementing res.render in an asynchronous fashion

My nodejs application is facing a bottleneck with the res.render method of express, which takes about 400 ms in a blocking manner. I'm looking for ways to handle this so it can execute in a non-blocking way. Running Apache benchmark on my setup shows ...

Deleting list items by clicking a button

I'm working on adding a functional "x" button to each list item (li) so that users can click on it to remove the item. I've successfully added the button, but I'm unsure about what code to use in the onClick event to delete the corresponding ...

Utilize the atan2() function to rotate a div so that it follows the movement of the mouse

I am trying to create an effect where the mouse aligns with the top of a div and the div rotates as the mouse moves. The rotation should happen when the top part of the div is in line with the mouse cursor. My goal is to achieve this using the atan2 functi ...

Error in JScript encountered during the downgrade to .NET Framework 2.0

Working on a Web Application project has brought about some challenges for me. Originally created in .NET 3.5, I recently found out that it has to be converted to .NET 2.0 (sigh). This transition not only caused issues with the LINQ functionalities but als ...

Placement of watermark label above specific elements to prevent interference with click propagation

I have developed a unique watermark/hint feature for a dropdown menu by positioning a label directly over the select element. However, I am facing an issue where users are unable to open the drop down when clicking on the label as it seems to block the cl ...

Creating a series of images in JavaScript using a for loop

Currently attempting to create an array of images, but with a large number of images I am looking into using a "for loop" for generation. Here is my current code snippet : var images = [ "/images/image0000.png", "/images/image0005.png", "/ima ...

Finding the value within a specified range of two numbers in Vue.js

When my code generates a result of 0, I need to determine the corresponding value based on the basic_salary. For example, if the basic_salary is 40,000, it should return the value of "ee": 400. <table class="table table-hover table-borde ...

Update the CSS styling for elements that are dynamically added to the page using the

Just started using jQuery for the first time and I'm encountering an issue. I'm trying to load content from an external element onto my page, and while it loads correctly, I'm having trouble using normal traversal methods on the loaded eleme ...

Utilize both a model and a boolean variable within expressionProperties in Formly configuration

I'm having trouble setting formly form fields to disabled based on model properties and a boolean variable. The code snippet I've tried doesn't seem to be working as expected. expressionProperties: { 'templateOptions.disabled' ...