offcanvas pushmenu for bootstrap
Instantly share code, notes, and snippets.
Last active
August 8, 2016 10:06
-
Star
0
(0)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save kiempoturner/e6f1ddd48a69cb0ba3394dfaa2eab039 to your computer and use it in GitHub Desktop.
Pushmenu for bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@media screen and (max-width: 1199px) { | |
.navbar-nav { | |
margin:0; | |
} | |
/* General styles for all menus */ | |
.cbp-spmenu { | |
background: #f8f8f8; | |
position: fixed; | |
padding:0; | |
margin:0 !important; | |
overflow-x:hidden; | |
overflow-y:visible; | |
display:block; | |
} | |
.cbp-spmenu h3 { | |
color: #afdefa; | |
font-size: 1.9em; | |
padding: 20px; | |
margin: 0; | |
font-weight: 300; | |
background: #0d77b6; | |
} | |
.cbp-spmenu a { | |
display: block; | |
} | |
/* Orientation-dependent styles for the content of the menu */ | |
.cbp-spmenu-vertical { | |
width: 260px; | |
height: 100%; | |
top: 0; | |
z-index: 1000; | |
} | |
.cbp-spmenu-horizontal { | |
width: 100%; | |
height: 150px; | |
left: 0; | |
z-index: 1000; | |
overflow: hidden; | |
} | |
.cbp-spmenu-horizontal h3 { | |
height: 100%; | |
width: 20%; | |
float: left; | |
} | |
.cbp-spmenu-horizontal a { | |
float: left; | |
width: 20%; | |
padding: 0.8em; | |
border-left: 1px solid #258ecd; | |
} | |
/* Vertical menu that slides from the left or right */ | |
.cbp-spmenu-left { | |
left: -260px; | |
} | |
.cbp-spmenu-right { | |
right: -260px; | |
} | |
.cbp-spmenu-left.cbp-spmenu-open { | |
left: 0px; | |
background-color: #1791c0; | |
} | |
.cbp-spmenu-right.cbp-spmenu-open { | |
right: 0px; | |
background-color: #024287; | |
} | |
/* Horizontal menu that slides from the top or bottom */ | |
.cbp-spmenu-top { | |
top: -150px; | |
} | |
.cbp-spmenu-bottom { | |
bottom: -150px; | |
} | |
.cbp-spmenu-top.cbp-spmenu-open { | |
top: 0px; | |
} | |
.cbp-spmenu-bottom.cbp-spmenu-open { | |
bottom: 0px; | |
} | |
/* Push classes applied to the body */ | |
.cbp-spmenu-push { | |
overflow-x: hidden; | |
position: relative; | |
left: 0; | |
} | |
.cbp-spmenu-push-toright { | |
left: 260px; | |
} | |
.cbp-spmenu-push-toleft { | |
left: -260px; | |
} | |
/* Transitions */ | |
.cbp-spmenu, | |
.cbp-spmenu-push { | |
-webkit-transition: all 0.3s ease; | |
-moz-transition: all 0.3s ease; | |
transition: all 0.3s ease; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="navbar navbar-default" role="navigation"> | |
<div class="navbar-header"> | |
<button type="button" class="navbar-toggle collapsed toggle-menu menu-right push-body" data-toggle="collapse" data-target="#navmenu"> | |
<span class="sr-only">Toggle navigation</span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
<span class="icon-bar"></span> | |
</button> | |
</div> | |
<div class="navbar-menu collapse cbp-spmenu cbp-spmenu-vertical cbp-spmenu-right" id="navmenu"> | |
<ul class="nav navbar-nav"> | |
<li class="menu1"><a href="#">About council </a></li> | |
<li class="menu2"><a href="#">Building and planning</a></li> | |
<li class="menu3"><a href="#">Clarence living</a></li> | |
<li class="menu4"><a href="#">Environment</a></li> | |
<li class="menu5"><a href="#">Jobs</a></li> | |
<li class="menu6"><a href="#">Our services</a></li> | |
<li class="menu7"><a href="#">Recreation</a></li> | |
<li class="menu8"><a href="#">Regulations and permits</a></li> | |
</ul> | |
</div> | |
</nav> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* jPushMenu.js | |
* 1.1.1 | |
* @author: takien | |
* http://takien.com | |
* Original version (pure JS) is created by Mary Lou http://tympanus.net/ | |
*/ | |
(function($) { | |
$.fn.jPushMenu = function(customOptions) { | |
var o = $.extend({}, $.fn.jPushMenu.defaultOptions, customOptions); | |
/* add class to the body.*/ | |
$('body').addClass(o.bodyClass); | |
$(this).addClass('jPushMenuBtn'); | |
$(this).click(function() { | |
var target = '', | |
push_direction = ''; | |
if($(this).is('.'+o.showLeftClass)) { | |
target = '.cbp-spmenu-left'; | |
push_direction = 'toright'; | |
} | |
else if($(this).is('.'+o.showRightClass)) { | |
target = '.cbp-spmenu-right'; | |
push_direction = 'toleft'; | |
} | |
else if($(this).is('.'+o.showTopClass)) { | |
target = '.cbp-spmenu-top'; | |
} | |
else if($(this).is('.'+o.showBottomClass)) { | |
target = '.cbp-spmenu-bottom'; | |
} | |
$(this).toggleClass(o.activeClass); | |
$(target).toggleClass(o.menuOpenClass); | |
if($(this).is('.'+o.pushBodyClass)) { | |
$('body').toggleClass( 'cbp-spmenu-push-'+push_direction ); | |
} | |
/* disable all other button*/ | |
$('.jPushMenuBtn').not($(this)).toggleClass('disabled'); | |
return false; | |
}); | |
var jPushMenu = { | |
close: function (o) { | |
$('.jPushMenuBtn,body,.cbp-spmenu').removeClass('disabled active cbp-spmenu-open cbp-spmenu-push-toleft cbp-spmenu-push-toright'); | |
} | |
} | |
if(o.closeOnClickOutside) { | |
$(document).click(function() { | |
jPushMenu.close(); | |
}); | |
$('.cbp-spmenu,.toggle-menu').click(function(e){ | |
e.stopPropagation(); | |
}); | |
} | |
}; | |
/* in case you want to customize class name, | |
* do not directly edit here, use function parameter when call jPushMenu. | |
*/ | |
$.fn.jPushMenu.defaultOptions = { | |
bodyClass : 'cbp-spmenu-push', | |
activeClass : 'menu-active', | |
showLeftClass : 'menu-left', | |
showRightClass : 'menu-right', | |
showTopClass : 'menu-top', | |
showBottomClass : 'menu-bottom', | |
menuOpenClass : 'cbp-spmenu-open', | |
pushBodyClass : 'push-body', | |
closeOnClickOutside: true | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment