Cyberswipe gives you primary and secondary drawer elements to organize your navigation, and is targeted at touchscreens 7" and up.
var mySwiper = new Cyberswipe({
drawerWidth: 250, // All units are in px
handleWidth: 60,
threshold: 50, // The threshold at which the drawer will snap open or shut
dragElement: document.getElementById('cyber-drag-handle'),
pushContent: false, // If set to true, content will be pushed over when nav drawer opens
nav: document.getElementsByTagName('nav')[0],
navContent: document.getElementsByClassName('cyber-drawer')[0],
contentContainer: document.getElementsByClassName('cyber-content-container')[0],
contentElement: document.getElementsByClassName('cyber-content')[0],
contentMargin: 10
});
mySwiper.open();
mySwiper.close();
mySwiper.isOpen();
index.html starter file with comments
Download the cyberswipe.js
file and save it. For newbies, save it in the same folder as your index.html
file, aka your root
directory.
Link to cyberswipe.js
before the closing </head>
tag:
<script src="cyberswipe.js"></script>
You will need the following styles, either between <style>
tags between the <head>
tags, or in your stylesheet:
nav {
position:fixed;
top: 0;
height:100%;
background-color:#FABD4A; /* your choice here */
z-index:3; /* make sure this is the highest z-index on the page */
}
.cyber-drawer {
-webkit-overflow-scrolling: touch;
overflow-y: auto;
position:relative;
top:0;
height:100%;
color:#002E40; /* your choice here */
}
.cyber-transition {
-webkit-transition:all 0.25s ease-in-out; /* for the .open() and .close() methods */
-moz-transition:all 0.25s ease-in-out; /* you can pick the timing */
-o-transition:all 0.25s ease-in-out;
transition:all 0.25s ease-in-out;
}
#cyber-drag-handle {
position: absolute;
top: 0;
right: 0;
height: 100%;
background-color: #2A5769; /* your choice here */
}
Use the following structure in the between the <body>
tags in your index.html
file:
<nav>
<div class="cyber-drawer">
<!-- Your Navigation Drawer Contents go here -->
</div>
<div id="cyber-drag-handle">
<!-- Your icons, buttons, and other primary navigational elements go here -->
</div>
</nav>
<div class="cyber-content-container">
<div class="cyber-content">
<!-- Your main page content goes here -->
</div>
</div>
Right before the closing </body>
tag, instantiate a new Cyberswipe
like this:
var mySwiper = new Cyberswipe(options);
The options
can be set with an object
. Here are the basic parameters with their defaults:
{
drawerWidth: 250, // All units are in px
handleWidth: 60,
threshold: 50, // The threshold at which the drawer will snap open or shut
dragElement: document.getElementById('cyber-drag-handle'),
pushContent: false // If set to true, content will be pushed over when nav drawer opens
}
Advanced users may find the following additional options useful. These may assist in re-structuring the HTML
tags, classes, and ids:
{
nav: document.getElementsByTagName('nav')[0],
navContent: document.getElementsByClassName('cyber-drawer')[0],
contentContainer: document.getElementsByClassName('cyber-content-container')[0],
contentElement: document.getElementsByClassName('cyber-content')[0],
contentMargin: 10
}
Now that you've instantiated a new Cyberswipe, you may want to use one of the following public methods in the rest of your JavaScript:
mySwiper.open();
mySwiper.close();
mySwiper.isOpen();
Brenda Jin is a developer in San Francisco, California specializing in mobile web app experiences.
This project was heavily inspired by the following microlibraries:
In addition, this project is grateful to the following people:
Copyright (c) 2013 Brenda Jin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
var myFirstCyberswipe = new Cyberswipe();