-
Notifications
You must be signed in to change notification settings - Fork 2
/
responsive-design-off-canvas.html
111 lines (107 loc) · 2.29 KB
/
responsive-design-off-canvas.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive Patterns - Off Canvas</title>
<style type="text/css">
html, body {
height: 100%;
width: 100%;
}
main {
background: aquamarine;
width: 100%;
height: 100%;
}
a#menu svg {
width: 40px;
fill: #000;
}
nav, main {
padding: 1em;
box-sizing: border-box;
}
/* For mobile-first, the off-canvas drawer is hidden. */
nav {
background: deepskyblue;
width: 300px;
height: 100%;
position: absolute;
-webkit-transform: translate(-300px, 0);
transform: translate(-300px, 0);
transition: transform 0.3s ease;
}
nav.open {
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
#desktop {
display: none;
}
/* The drawer stays open if width > 600px */
@media screen and (min-width: 600px) {
nav {
position: relative;
-webkit-transform: translate(0, 0);
transform: translate(0, 0);
}
body {
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-flow: row nowrap;
flex-flow: row nowrap;
}
main {
width: auto;
-webkit-flex-grow: 1;
flex-grow: 1;
}
#desktop {
display: block;
}
#mobile {
display: none;
}
#drawer p {
display: none;
}
}
</style>
</head>
<body>
<nav id="drawer">
<h3>Off Canvas Drawer</h3>
<p>Click outside the sliding drawer to close.</p>
</nav>
<main>
<div id="mobile">
<a id="menu">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M2 6h20v3H2zm0 5h20v3H2zm0 5h20v3H2z"></path>
</svg>
</a>
<p>Click on the hamburger menu icon to open the sliding drawer.</p>
</div>
<div id="desktop">
<h3>Main</h3>
<p>Resize the window to the mobile view width of 600px or less to hide the sliding drawer.
</p>
</div>
</main>
<script>
var menu = document.querySelector('#menu');
var main = document.querySelector('main');
var drawer = document.querySelector('#drawer');
menu.addEventListener('click', function(e) {
drawer.classList.toggle('open');
e.stopPropagation();
});
main.addEventListener('click', function() {
drawer.classList.remove('open');
});
</script>
</body>
</html>