Enhance Your Website with Dynamic Navigation Animation

Seeking assistance with animating a navigation bar on and off the screen from the left side. The nav is not animating as expected using the latest version of jquery.min.js. The first step was to animate the nav upon clicking an object. View the current progress on JSFiddle:

Here is the current code:

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="../CSS/Default.css" />
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript" src="../JS/Script.js"></script>
    </head>
    <body>
        <h1 class="menu-open" id="open">Open</h1>
        <div class="nav" id="nav">
            <div class="menu">
                <h1>Menu</h1>
                 <div class="elements">
                    <h2 class="home"><a href="#">Home</a></h2>
                    <h2 class="about"><a href="#">About</a></h2>
                    <h2 class="code"><a href="#">Products</a></h2>
                    <h2 class="design"><a href="#">Contact</a></h2>
                    <h2 class="gaming"><a href="#">Find Us</a></h2>
                    <h2 class="more"><a href="#">More</a></h2>
                </div>
            </div>
        </div>
    </body>
</html>

JQuery:

var main = function(){
    $('.open').click(function(){
        $('.nav').animate({
            left: "0px"
        }, 200);
    });
};
$(document).ready(main);

CSS:

body{
    margin: 0 auto;
}
.nav{
    top:0;
    left: -300px;
    z-index: 1;
    position: fixed;
    height:100%;
    width:300px;
    background-color: #336ca6;
}
.menu-open{
    position:absolute;
    left:500px;
    cursor: pointer;
}
.menu{
    font-family: arial;
    width:300px;
}
.menu h1{
    position:relative;
    left:100px;
    color: #a0a0a0;
}
.menu h2 {
    border-bottom: 1px solid #aaaaaa;
    padding-left:20px;
    padding-bottom:20px;
    width:280px;
}
.menu .elements{
    margin-top:35px;
}
.menu a{
    text-decoration: none;
    font-family: arial;
    color:#efefef;
    width:300px;
}
.menu a:hover{
    color:#aaaaaa;
    transition:color 0.5s;
}
.menu .home{
    border-top: 1px solid #aaaaaa;
    padding-top:20px;
}

Any help would be greatly appreciated!

Answer №1

It's actually quite simple. The issue is that you used ".open" in your script when open is actually an id... you need to change

$('#open').click(function() /*replace the . with # */

try that and it should work

http://jsfiddle.net/a7fkp785/3/

Answer №2

The process can be simplified even further by incorporating a class that utilizes css3 transitions

.menu{
    top:0;
    left: -200px;
    z-index: 1;
    position: fixed;
    height:100%;
    width:200px;
    background-color: #5f3a6e;
    transition: all 0.3s;/*UPDATED*/
}
.slide-menu{
    left:0;
}

JAVASCRIPT

$('#toggle').click(function(){
    $('.menu').toggleClass('slide-menu');
});

LIVE DEMO

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

Activate the dialog box exclusively after data has been submitted via the submit button on a form

My goal is to create a data saving functionality with a next button. After filling out the form, clicking on the next button triggers a popup dialog asking, "Do you want to submit your data?" To achieve this, I included the following code in my submit but ...

Skrollr immediate pop-up notification

Can anyone help me figure out how to make text appear suddenly and then disappear using skrollr? I've been able to get it to fade in and out, but I want it to just show up without any transition. Here's the code I have so far: <div id="style" ...

Having issues with the background-image style not displaying correctly in the header of an

Trying to update the "background-image:" of a CSS class upon button click. JQuery: $(function() { $('button').on('click', function() { $('.masthead2').css('background-image', 'url("../img/whitehead ...

What is the process for determining the total size of all files uploaded in dropzone?

How can I calculate the total size of all files uploaded in dropzone? For example, if I select 5 files each with a size of 2mb, the total size should be returned as 10mb. Also, I would like to restrict the total size of all files if it exceeds a certain ...

Determine the Height of the Container once the Font File has Finished Loading

When styling a website with a unique font using @font-face, the browser must download the font file before it can display the text correctly, similar to how it downloads CSS and JavaScript files. This poses an issue in Chrome (v16.0.912.63) and Safari (v5 ...

Adding the most recent version of jquery causes the webpage to malfunction

Currently, I am facing a challenge on a website that has an outdated version of jQuery (1.7.2) included in the header. In order to use a plugin that requires the latest version of jQuery, I tried linking the newer version (2.1.3) in the footer. However, j ...

Utilizing AJAX Requests in jQuery Widget Elements for an Interactive Dashboard

I recently implemented the jQuery Dashboard plugin on my site to showcase information from a MySql table. Each widget contains buttons corresponding to the results, which when clicked trigger an ajax call to fetch and display a styled form in a jQuery dial ...

The challenge of applying flex property in React Native JSX

I'm facing a challenge while trying to implement form field validation in various forms within a React Native mobile application. The problem arises when the error message, which should appear below the text input field, ends up occupying half of the ...

Developing a custom styling class using JavaScript

Looking to create a custom style class within JavaScript tags. The class would look something like this: #file-ok { background-image: url(<?php echo json.get('filename'); ?>); } Essentially, the value returned from the PHP file (json ...

Identifying the differences between a select2 dropdown and select2 multiselect: a guide

I currently have two different controls on my page: a select2 dropdown and a jquery multi value select Select2 Dropdown <select id="drp_me" class="select2-offscreen"> <option value="1">one</option> <option value="2">two</op ...

What is the best way to retrieve the nearest form data with jQuery after a child input has been modified?

I have a page with multiple forms, each containing several input checkboxes. When one of the form inputs changes, I want to gather all the parent form's data into a JSON array so that I can post it elsewhere. I'm having trouble putting the post ...

Is it possible to combine form elements into a unified object structure?

Currently, I am working on a project where I need to aggregate form elements into an object and then send it via Ajax. Here is the code snippet that I have started using, but I am stuck on how to proceed further. $('.jcart').live('submit&ap ...

Display a designated loader when making a particular AJAX request

I am currently implementing a jQuery code to display a loader. Within my form, I have two AJAX calls - one triggered by an input field and the other by a submit button. Both of these calls refer to the same DIV id for displaying the loader. The issue I&apo ...

Implementing MVC architecture in web development allows for the encryption of parameters sent

I have a scenario where I'm utilizing an ajax call to trigger my action method. The call involves sending two parameters, and I aim to secure/ encrypt these parameters before transmitting them to the action method, then decrypting those values within ...

Implementing a dynamic update of an HTML element's content with JSON data - Learn how!

My task involves creating a quiz application where I need to show the answers along with images of the choices stored in my JSON data. However, I encounter an error: Uncaught TypeError: Cannot set properties of null (setting 'src') when I attempt ...

Ways to identify when a person has scrolled a specific distance

Is it possible to modify the appearance of my top navigation bar once the page has been scrolled a specific number of pixels? I assume this requires some sort of listener to track the amount of scrolling. I came across element.scrollTop, but it doesn' ...

Defining variables within a jQuery function

Within my initialization function (init), I have defined some variables and an animation that utilizes those variables. The challenge arises when I want to use the same animation/variables in my clickSlide function. http://jsfiddle.net/lollero/4WfZa/ (Un ...

Tips for obtaining user input to place markers on a video timeline with JavaScript

I am new to Java script and I am trying to create a video player where users can click on the progress bar to place markers. Can you please review my code below and let me know if there are any errors? index.html <!doctype html> <html> <he ...

Internet Explorer 9 (IE9) causing CSS dropdown menu to be truncated due

My issue is very similar to the problem described in this post: CSS Flyout menu gets cut off by borders of its container in IE9 The difference in my case is that I need to set the z-index (and position) on the container. You can view my JSFiddle here: h ...

Tips for updating the hover background color of a table row with a unique class in bootstrap

Modified: Here is the table along with its corresponding CSS styling: .table-hover tbody tr:hover { background-color: #fff !important; } <html lang="en"> <head> <meta charset="utf-8" /> <meta name="v ...