This is my code:
JavaScript
x
21
21
1
<!doctype html>
2
<html lang="en-US">
3
<head>
4
<title>Welcome - Home</title>
5
<link type="text/css" rel="stylesheet" href="Home.css">
6
<link rel="icon" href="KLOGO.png" type="image/png"/>
7
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
8
<script src="Home.js"></script>
9
</head>
10
<body class="menu">
11
<header>
12
<a href="#" class="menu-toggle">Toggle</a>
13
<nav class="menu-side">
14
This is a side menu
15
</nav>
16
</header>
17
<p> sioeufh iufha dgrkljbgril unfvuabervluiyboyubn serlibglisuhsefiuh oaisuf aieufh aosih asioeufh iufha dgrkljbgril unfvuabervluiyboyubn serlibglisu</p>
18
<p>oierua yugafapiwugText and more tejiaslirfuh aiufh oaiuefhioaushf aisbhfailsubfaufha dgrkljbgril unfvuabervluiyboyubn serlibglisuh oaiusg foiygasdefoiawg pghuioyf gaiwuebfyaweoilru gfa s7ierfygasrgoooa8iweygfra iiiastygf a8we8</p>
19
</body>
20
</html>
21
The css:
JavaScript
1
20
20
1
.menu-side{
2
background: #333;
3
border-right: 1px solid #000;
4
color: #fff;
5
position: fixed;
6
top: 0;
7
left: -231px;
8
width: 210px;
9
height: 100%;
10
padding: 10px;
11
}
12
.menu{
13
overflow-x:hidden;
14
position: relative;
15
left: 0px;
16
}
17
.menu-open {
18
left: 231px;
19
}
20
And the jquery:
JavaScript
1
8
1
(function () {
2
var body = $('body');
3
$('.menu-toggle').bind('click', function () {
4
body.toggleClass('menu-open');
5
return false;
6
});
7
})();
8
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.
Advertisement
Answer
Put <script src="Home.js"></script>
before the </body>
tag.
I made another class
JavaScript
1
4
1
.menu-side-open{
2
left:0px;
3
}
4
and JQuery
JavaScript
1
9
1
(function () {
2
var body = $('body');
3
$('.menu-toggle').bind('click', function () {
4
body.toggleClass('menu-open');
5
$('.menu-side').toggleClass('menu-side-open');
6
return false;
7
});
8
})();
9
Also added
JavaScript
1
4
1
.menu, .menu-side{
2
transition: 300ms;
3
}
4
for a nice slide 🙂