0

This is my code:

<!doctype html>
<html lang="en-US">
<head>
    <title>Welcome - Home</title>
    <link type="text/css" rel="stylesheet" href="Home.css">
    <link rel="icon" href="KLOGO.png" type="image/png"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
    <script src="Home.js"></script>
</head>
<body class="menu">
    <header>
        <a href="#" class="menu-toggle">Toggle</a>
        <nav class="menu-side">
            This is a side menu
        </nav>
    </header>
    <p> sioeufh iufha dgrkljbgril unfvuabervluiyboyubn serlibglisuhsefiuh oaisuf aieufh aosih asioeufh iufha dgrkljbgril unfvuabervluiyboyubn serlibglisu</p>
    <p>oierua yugafapiwugText and more tejiaslirfuh aiufh oaiuefhioaushf aisbhfailsubfaufha dgrkljbgril unfvuabervluiyboyubn serlibglisuh oaiusg foiygasdefoiawg pghuioyf gaiwuebfyaweoilru gfa s7ierfygasrgoooa8iweygfra iiiastygf a8we8</p>
</body>
</html>

The css:

    .menu-side{
    background: #333;
    border-right: 1px solid #000;
    color: #fff;
    position: fixed;
    top: 0;
    left: -231px;
    width: 210px;
    height: 100%;
    padding: 10px;
}
.menu{
    overflow-x:hidden;
    position: relative;
    left: 0px;
}
.menu-open {
    left: 231px;
}

And the jquery:

(function () {
var body = $('body');
$('.menu-toggle').bind('click', function () {
    body.toggleClass('menu-open');
    return false;
});
})();

I'm using the Brackets program to write my code, but when I go to the live view after I saved everything and i press "toggle" the page wont move and I looked over everything and Im 98% sure its correct.

4
  • any console errors in your browser console?? Commented Aug 9, 2015 at 18:21
  • Uncaught ReferenceError: $ is not defined(anonymous function) @ Home.js:2(anonymous function) @ Home.js:7 Home.html:9 The value "divice-width" for key "width" is invalid, and has been ignored. 127.0.0.1:49873/Home/KLOGO.png Failed to load resource: the server responded with a status of 404 (Not Found) Commented Aug 9, 2015 at 18:23
  • Did you forget to close the viewport meta tag only here or in your code too? Commented Aug 9, 2015 at 18:23
  • 2
    you havent included jquery in your page.. Commented Aug 9, 2015 at 18:23

4 Answers 4

1

Put <script src="Home.js"></script> before the </body> tag.

I made another class

.menu-side-open{
    left:0px;
}

and JQuery

(function () {
var body = $('body');   
$('.menu-toggle').bind('click', function () {
    body.toggleClass('menu-open');
    $('.menu-side').toggleClass('menu-side-open');
    return false;
});
})();

Also added

.menu, .menu-side{
    transition: 300ms;
}

for a nice slide :)

JSFiddle demo

Sign up to request clarification or add additional context in comments.

Comments

1

You need to include jQuery if you want to use it.

Add this line

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>

In your html's head or before you use jQuery!

e.g.

<head>
    <title>Welcome - Home</title>
    <link type="text/css" rel="stylesheet" href="Home.css">
    <link rel="icon" href="KLOGO.png" type="image/png"/>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
    <script src="Home.js"></script>

Comments

0

Change this:

body.toggleClass('menu-open');

to this:

$('.menu-side').toggleClass('menu-open');

And change the .menu-open css class to this:

.menu-open {
    top:10%;
    left: 0px;
}

Here is the JSFiddle demo

Its the .menu-side that is hidden on the left. Therefore you should be applying the menu-open class to .menu-side and not the body tag.

Your CSS was setting the left of .menu-side to 231px, setting it back to 0px is enough to make the menu appear back into view. And when the menu appeared, it covered the 'Toggle' link, therefore I also added top:10% to the .menu-open class CSS.

2 Comments

3 JSLint Problems × 2 Missing 'use strict' statement. var body = $('body'); 2 '$' was used before it was defined. var body = $('body'); 7 Move the invocation into the parens that contain the function. })()
yeah, that just checking a valid format of the code. I tried to keep it close to your original code, but here is an updated version of the code. You will have to declare jQuery as a global variable for JSLint validation
0

I think it is related to a missing file from the computer. I have the same issue with my computer and it does not really matter wether you put the CSS and JS into the HTML page. The result will be the same. When you open the page in the browser, you won`t see any changes, and if I press F12 it says: Failed to load resource: net::ERR_FILE_NOT_FOUND or dll file not found or something like that

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.