Location appearing feature activated by clicking on navigation buttons

I've been having trouble getting the navigation locations to appear and disappear. I'm not very familiar with JavaScript, but I suspect that's the issue. My goal is to make the locations (WebDesign, Photography, SketchUp, Photoshop, About, Home) appear when I click on the three bars icon. Transforming the bars into a cross shape works fine.

function rotatebar(x) {
            x.classList.toggle("rotate");
        }
.navigation {
    display: inline-block;
    float: right;
    cursor: pointer;
    margin-top: 80px;
    margin-right: 120px;
}
.stripes {
    float: right;
}
.bar1, .bar2, .bar3 {
    width: 30px;
    height: 2px;
    background-color: #fff;
    transition: 0.2S;
}

/* nav button movement */
.bar2, .bar3 {
    margin-top: 7px;
}
.rotate .bar1 {
    -webkit-transform: rotate(-45deg);
    transform: rotate(-45deg) translate( -5px, 7px);
}
.rotate .bar3 {
   -webkit-transform: rotate(45deg);
    transform: rotate(45deg) translate( -6px, -7px); 
}
.rotate .bar2 {
    opacity: 0;
}

/* nav locations */
.navloc {
    display: inline;
    color: #fff;
    font-family: Open sans;
    text-align: center;
    cursor: pointer;
    margin-right: 30px;
    transition: 0.2S;
}
.loc {
    margin: 0;
    padding: 0;
    float: left;
    margin-left: 30px;
    cursor: pointer;
}
.loc:hover {
    color: #ff0000;
    border-bottom: 2px solid;
    margin-bottom: -2px;
}

/* nav locations movement */

.rotate .navloc {
    opacity: 1;
}
<div class="navigation" onclick="rotatebar(this)">
    <div class="navloc"> 
        <p class="loc">WebDesign</p>
        <p class="loc">Photography</p>
        <p class="loc">SketchUp</p>
        <p class="loc">Photoshop</p>
        <p class="loc">About</p>
        <p class="loc">Home</p>
    </div>                     
    <div class="stripes">
        <div class="bar1"></div>
        <div class="bar2"></div>
        <div class="bar3"></div>
    </div>
</div>  

Answer №1

To achieve the desired effect, make sure to include .navlov with the properties opacity: 0 and display: inline-block in your CSS code. I have provided a functional snippet for reference.

 function rotatebar(x) {
            x.classList.toggle("rotate");
        
        }
body {
  background: #000;
} 
.navigation {
                display: inline-block;
                float: right;
                cursor: pointer;
                margin-top: 80px;
                margin-right: 120px;
            }
            .stripes {
                float: right;
            }
            .bar1, .bar2, .bar3 {
                width: 30px;
                height: 2px;
                background-color: #fff;
                transition: 0.2s;
            }

            /* nav button movement */
            .bar2, .bar3 {
                margin-top: 7px;
            }
            .rotate .bar1 {
                -webkit-transform: rotate(-45deg);
                transform: rotate(-45deg) translate(-5px, 7px);
            }
            .rotate .bar3 {
                -webkit-transform: rotate(45deg);
                transform: rotate(45deg) translate(-6px, -7px); 
            }
            .rotate .bar2 {
                opacity: 0;
            }

            /* nav locations */
            .navloc {
                display: inline-block;
                color: #fff;
                font-family: Open sans;
                text-align: center;
                cursor: pointer;
                margin-right: 30px;
                transition: 0.2s;
            }
            .loc {
                margin: 0;
                padding: 0;
                float: left;
                margin-left: 30px;
                cursor: pointer;
            }
            .loc:hover {
                color: #ff0000;
                border-bottom: 2px solid;
                margin-bottom: -2px;
            }

            /* nav locations movement */
.navloc {
                opacity: 0;
            }
            .rotate .navloc {
                opacity: 1;
            }
<div class="navigation" onclick="rotatebar(this)">
                <div class="navloc"> 
                    <p class="loc">WebDesign</p>
                    <p class="loc">Photography</p>
                    <p class="loc">SketchUp</p>
                    <p class="loc">Photoshop</p>
                    <p class="loc">About</p>
                    <p class="loc">Home</p>
                </div>                     
                <div class="stripes">
                    <div class="bar1"></div>
                    <div class="bar2"></div>
                    <div class="bar3"></div>
                </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

Adding to and retrieving data from an array

I am relatively new to the world of JavaScript and jQuery, and I have spent the last three days working on a script. Despite my efforts to find a solution by searching online, I have been unsuccessful so far. It seems like my search skills are lacking. My ...

add the elements of an array to multiple div elements sequentially

I'm attempting to update all titles in .item with the values from array. The array I am using contains the following elements: var itCats = ['one', 'two', 'three', 'four']; Additionally, this is the HTML struc ...

Pressing the enter key will submit the form

After receiving feedback from users in my live chat room, one common request was to add a feature that allows them to send a message by pressing the enter button, instead of creating a new line in the text box. Despite attempting to implement some jQuery ...

How can you make the coordinates of the cursor track the cursor when it hovers over a rectangle?

The code provided below will constantly display the cursor's coordinates right below the cursor: function displayCursorCoordinates(e) { var x = event.clientX; var y = event.clientY; var coordinates = "(" + x + ", " + y + ")"; document.getEl ...

angular model bind include move

I'm working on developing custom elements that will transform my form elements to match the styling structure of Bootstrap's forms. Essentially, <my-input ng-model="myname"> should be transformed into <div class="form-element"> ...

Three.js globe experiencing issues with splines arc functionality

I have been experimenting with mapping arcs around a three.js globe, following some examples. I am close to getting it to work but I am struggling with the calculations and the resulting projection appears to be incorrect. If anyone could review my code an ...

Testing a cucumber scenario by comparing the redirect URL with a different URL

Currently, I am working on writing Cucumber tests for my project. One issue I have encountered is that when clicking a certain button in my code, it redirects to another page with a fixed URL. How can I retrieve the current URL within the Cucumber test? I ...

interrupt the node script using async behavior

I encountered an issue while running the npm install command to install a list of modules on Node, specifically related to async. TypeError: undefined is not a function What could be causing this problem? var fs = require( "fs" ), path = require( ...

Converting JQuery Object (Ajax-response) to an Array Containing Keys and Values

When I make an $.ajax request, the response I receive looks like this: https://i.sstatic.net/UfnfQ.jpg (please don't worry about the Russian symbols, they are just strings of text:)) I am aware that when PHP sends the request, it is in a simple arr ...

Handling errors in chained promises and routes in Node.js/ExpressJS

I'm currently dealing with some confusion regarding how to handle errors when making function calls. To demonstrate this, I'll be using sequelizeJS as an example. Usually: First.Ctrl var second_ctrl = require( '../ctrl/second'); testC ...

"Exploring the Functionality of Dropdown Menus in ASP.NET Core 1

Looking for a unique way to create a dropdown menu in ASP.Net Core 1.0? I've scoured the internet but haven't found a solution specifically tailored to this new platform. Can anyone provide guidance on how to build a large dropdown menu in Core 1 ...

Resolving Challenges with AngularJS Form Validation and Submission

I am currently working on a project using AngularJS where the user can activate their account, input their data, and submit JSON data upon completion. My Goal: When the user submits valid user data (within the JSON data), they should be redirected to &a ...

Having trouble styling my Aside element correctly

I'm having trouble aligning my aside element on the page. It's not lining up properly with the rest of the content and is overlapping into the header area. How can I resolve this issue? Here's a snapshot of what it currently looks like: ht ...

Unable to use the same hexadecimal HTML entity in the value props of a React JSX component

Can someone explain why this code snippet displays dots as password and the other displays plain hexadecimal codes? <Field label="Password" value="&#x2022;&#x2022;&#x2022;&#x2022;&#x2022;" type="password" /> While this one disp ...

The hyperlink functionality is disabled because Javascript is set to return false

JS Fiddle Example When using the 'FOO' and 'BOO' items in the navigation bar to open dropdown boxes, I have implemented a code that closes them when a click event occurs outside. This code has been working fine as shown below: $(docum ...

Updating a single document in Node JS using Express is a simple and straightforward process

I'm having trouble understanding why my documents aren't updating. When I retrieve any record and load it into the form using http://localhost:3000/update2?buyerID=2299, the field doesn't update when I make changes and click submit. It rema ...

If I choose a different option from the dropdown list, I would like a textbox to appear

Hey there, I have a list of industries and one of the options is "Other". When a user clicks on "Other", a text box should appear for them to specify. I'm struggling to make this work using Django AJAX. Any help would be appreciated! <div class ...

Preloading images before loading a div using JavaScript

Can you walk me through implementing object first and then mergeObject in JavaScript? I have an interesting scenario where I need to display the original list followed by a merged list after a short delay. How can I achieve this using JavaScript? Specific ...

Concerns with JavaScript Scope

I'm currently working on a function that I need help with. The function seems pretty straightforward to me: function CheckFile(path){ var status = false; $.ajax({ url: "http://mydomain.com/"+path, type: "HEAD", s ...

Tips for aligning three <p> elements side by side using flexbox

I need assistance with aligning three boxes next to each other, each containing an image, header, and text. The issue arises when resizing the browser, causing the content in box 2 and 3 to be positioned higher than box 1. Below is the code I have been us ...