Push in sidebar/menu from left
by Arete
HTML
<script type="text/javascript">
(function(window) {
'use strict';
/**
* Extend Object helper function.
*/
function extend(a, b) {
for (var key in b) {
if (b.hasOwnProperty(key)) {
a[key] = b[key];
}
}
return a;
}
/**
* Each helper function.
*/
function each(collection, callback) {
for (var i = 0; i < collection.length; i++) {
var item = collection[i];
callback(item);
}
}
/**
* Menu Constructor.
*/
function Menu(options) {
this.options = extend({}, this.options);
extend(this.options, options);
this._init();
}
/**
* Menu Options.
*/
Menu.prototype.options = {
wrapper: '#o-wrapper', // The content wrapper
type: 'slide-left', // The menu type
menuOpenerClass: '.c-button', // The menu opener class names (i.e. the buttons)
maskId: '#c-mask' // The ID of the mask
};
/**
* Initialise Menu.
*/
Menu.prototype._init = function() {
this.body = document.body;
this.wrapper = document.querySelector(this.options.wrapper);
this.mask = document.querySelector(this.options.maskId);
this.menu = document.querySelector('#c-menu--' + this.options.type);
this.closeBtn = this.menu.querySelector('.c-menu__close');
this.menuOpeners = document.querySelectorAll(this.options.menuOpenerClass);
this._initEvents();
};
/**
* Initialise Menu Events.
*/
Menu.prototype._initEvents = function() {
// Event for clicks on the close button inside the menu.
this.closeBtn.addEventListener('click', function(e) {
e.preventDefault();
this.close();
}.bind(this));
// Event for clicks on the mask.
this.mask.addEventListener('click', function(e) {
e.preventDefault();
this.close();
}.bind(this));
};
/**
* Open Menu.
*/
Menu.prototype.open = function() {
this.body.classList.add('has-active-menu');
this.wrapper.classList.add('has-' +...
CSS
/*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
The Common CSS
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]*/
.c-menu { position: fixed; z-index: 200; transition: transform 0.3s; }
.c-menu__close { box-shadow: none; -webkit-appearance: none; -moz-appearance: none; appearance: none; cursor: pointer; }
.c-menu__close:focus { outline: none; }
body.has-active-menu { overflow: hidden; }
.c-mask { position: fixed; z-index: 100; top: 0; left: 0; overflow: hidden; width: 0; height: 0; opacity: 0; transition: opacity 0.3s, width 0s 0.3s, height 0s 0.3s; }
.c-mask.is-active { width: 100%; height: 100%; opacity: 0.7; transition: opacity 0.3s; }
/*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
LEFT AND RIGHT MENUS
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]*/
.c-menu--push-left { width: 100%; height: 100%; overflow-y: scroll; }
@media all and (min-width:320px) {
.c-menu--push-left { width: 300px; }
}
.c-menu--push-left .c-menu__close { display: block; padding: 12px 24px; width: 100%; }
/*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
SLIDE AND PUSH LEFT
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]*/
.c-menu--push-left { top: 0; left: 0; transform: translateX(-100%); }
@media all and (min-width:320px) {
.c-menu--push-left { transform: translateX(-300px); }
}
.c-menu--push-left.is-active { transform: translateX(0); }
/*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
Left & Right Push Menus - Wrapper...