HTML5 is now too powerful to satisfy its appetite on the PC. It is going to make a big push into mobile, so all kinds of effects on mobile will be implemented in HTML5. Let’s see what slideout.js can do for us
First take a look at the running effect:
1. Prepare materials
Just prepare the slideout.js library:
Github.com/Mango/slide…
The small icon:
1) menu. PNG
Two, implementation code
HTML code:
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="Width = device - width, initial - scale = 1.0">
<title>Suitable for mobile phone sidebar slide code - webmaster material</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<nav id="menu" class="menu">
<a href="#" target="_blank">
<header class="menu-header">
<span class="menu-header-title">The theme</span>
</header>
</a>
<section class="menu-section">
<h3 class="menu-section-title">Script code</h3>
<ul class="menu-section-list">
<li><a href="#" target="_blank">jQuery</a></li>
<li><a href="#" target="_blank">CSS3</a></li>
<li><a href="#" target="_blank">HTML5</a></li>
<li><a href="#" target="_blank">Animation effects</a></li>
</ul>
</section>
<section class="menu-section">
<h3 class="menu-section-title">Flash animation</h3>
<ul class="menu-section-list">
<li><a href="#" target="_blank">Animation festival</a></li>
<li><a href="#" target="_blank">Flash plants</a></li>
<li><a href="#">Flash animals</a></li>
</ul>
</section>
<section class="menu-section">
<h3 class="menu-section-title">Download audio</h3>
<ul class="menu-section-list">
<li><a href="#" target="_blank">A bird</a></li>
<li><a href="#" target="_blank">The dog barked</a></li>
</ul>
</section>
</nav>
<main id="main" class="panel">
<button class="btn-hamburger js-slideout-toggle">
<span class="tooltip">Click on the open</span>
</button>
</main>
<script type="text/javascript" src="js/slideout.min.js"></script>
<script type="text/javascript">
var slideout = new Slideout({
'panel': document.getElementById('main'),
'menu': document.getElementById('menu'),
'padding': 256.'tolerance': 70
});
document.querySelector('.js-slideout-toggle').addEventListener('click'.function() {
slideout.toggle();
});
document.querySelector('.menu').addEventListener('click'.function(eve) {
if (eve.target.nodeName === 'A') { slideout.close(); }});</script>
</body>
</html>Copy the code
Structure code a simple, mainly pay attention to the use of slideout, it passed several parameters:
Panel: Refers to the main panel and refers to the entire content display area
Menu: refers to the hidden left menu bar area
Padding: The distance to the right after clicking the button
The CSS code:
html.body {
width: 100%;
height: 100%;
font: 100%/1.4 em 'Calibre Light'.'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 0 auto;
color: # 222;
-webkit-text-size-adjust: none;
-webkit-font-smoothing: antialiased;
}
pre {
margin: 0;
font-size: 14px;
}
body..panel {
background-color: #fff;
}
.menu {
background-color: #1D1F20;
background-image: linear-gradient(145deg, #1D1F20, #404348);
}
a {
color: #4B5;
text-decoration: none;
}
.menu a {
color: #fff;
}
.menu a:hover {
text-decoration: underline;
}
.menu-header {
border-bottom: 1px solid #2a2d2f;
padding: 20px 0 20px 60px;
background: url('.. /images/github.png') no-repeat 15px 15px;
background-size: 32px;
}
.menu-header-title {
font-weight: 400;
letter-spacing: 0.5 px.;
margin: 0;
}
.menu-section {
margin: 25px 0;
}
.menu-section-title {
text-transform: uppercase;
color: #85888d;
font-weight: 200;
font-size: 13px;
letter-spacing: 1px;
padding: 0 20px;
margin:0;
}
.menu-section-list {
padding:0;
margin: 10px 0;
list-style:none;
}
.menu-section-list a {
display: block;
padding: 10px 20px;
}
.menu-section-list a:hover {
background-color: rgba(255, 255, 255, 0.1);
text-decoration: none;
}
.panel {
text-align: center;
padding-top: 5px;
min-height: 100%;
}
/** * hamburger */
.btn-hamburger {
border: none;
position: absolute;
top: 12px;
left: 12px;
outline:none;
background: url('.. /images/menu.png') no-repeat left center;
}
.tooltip {
font-size: 20px;
line-height: 19px;
display: inline-block;
background: #4B5 url('.. /images/happy.png') no-repeat 135px 15px;
color: #fff;
padding: 10px 45px 10px 20px;
border-radius: 4px;
position: relative;
left: 50px;
}
/** * Medium Screens */
@media all and (min-width:40em) {
.btn-hamburger {
top: 20px;
left: 30px;
}
.panel-header {
margin-top: 40px;
width: 455px;
}
.title {
font-size: 4.2 em;
}
.subtitle {
font-size: 1.8 em;
}
.btn-download {
margin-right: 20px;
}
.btn-fork {
margin-left: 20px; }}.menu..slideout-menu {
position: fixed;
left: 0;
top: 0;
bottom: 0;
right: 0;
z-index: 0;
width: 256px;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
display: none;
}
.panel..slideout-panel {
position: relative;
z-index: 1;
}
.slideout-open..slideout-open body {
overflow: hidden;
}
.slideout-open .slideout-menu {
display: block;
}Copy the code
The CSS code above may be a bit redundant, but we don’t need to care so much about the details