A three dimensional and space effecient menu
A three dimensional and space effecient menu. Meny works best in browsers with support for CSS 3D transforms, although it falls back on 2D animation for older browsers. Supports touch events for mobile devices.
Add meny.js to your project. The meny.js file is the only thing required, but you could optionally clone the repository if you want to get the default styles.
Alternatively you can load the meny.js file from cdnjs, see https://cdnjs.com/libraries/meny.
Meny requires two HTML elements to work: a menu and the page contents. The class names are not used by the library so choose anything you want.
<body>
<div class="meny">
<!-- your menu items -->
</div>
<div class="contents">
<!-- your page contents -->
</div>
</body>
Some rules, notes and best practices to keep in mind in terms of markup and styling:
Next you need create an instance of Meny and tell it which HTML elements to use. This should be done after the meny.min.js is included on your page. Example using the HTML above:
var meny = Meny.create({
// The element that will be animated in from off screen
menuElement: document.querySelector( '.meny' ),
// The contents that gets pushed aside while Meny is active
contentsElement: document.querySelector( '.contents' ),
// The alignment of the menu (top/right/bottom/left)
position: 'left',
// The height of the menu (when using top/bottom position)
height: 200,
// The width of the menu (when using left/right position)
width: 260,
// The angle at which the contents will rotate to.
angle: 30,
// The mouse distance from menu position which can trigger menu to open.
threshold: 40,
// Width(in px) of the thin line you see on screen when menu is in closed position.
overlap: 6,
// The total time taken by menu animation.
transitionDuration: '0.5s',
// Transition style for menu animations
transitionEasing: 'ease',
// Gradient overlay for the contents
gradient: 'rgba(0,0,0,0.20) 0%, rgba(0,0,0,0.65) 100%)',
// Use mouse movement to automatically open/close
mouse: true,
// Use touch swipe events to open/close
touch: true
});
A few handy methods API methods are included, you call these on the instance returned by Meny.create
(see above).
meny.configure({ mouse: false }); // change settings after initialization
meny.open();
meny.close();
meny.isOpen(); // true/false
meny.destroy(); // revert original DOM state, unbind events
The wrapper element (parent of the menu and contents) is decorated with classes based on its state:
.meny-active
.meny-top
.meny-right
.meny-bottom
.meny-left
Instances of Meny dispatch events to notify you of their state:
var meny = Meny.create( ... ) // see 3. Initialize
meny.addEventListener( 'open', function() {
// do something on open
} );
meny.addEventListener( 'close', function() {
// do something on close
} );
meny.addEventListener( 'opened', function() {
// do something right after meny is opened and transitions finished
} );
meny.addEventListener( 'closed', function() {
// do something right after meny is closed and transitions finished
} );
opened
and closed
eventsdestroy
API methodtouch
and mouse
config optionsconfigure
API method for changing settings at runtimeMIT licensed
Copyright © 2014 Hakim El Hattab, http://hakim.se