Advertisement
Venelin

Push Menu

Jun 15th, 2016
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. ==================
  2. HTML:
  3.  
  4. <body>
  5. <div id="overlayContainer"></div>
  6. <div class="side-menu side-menu--left">
  7. <a href="#" class="side-menu__close jsCloseUserMenu" data-side="left">close</a>
  8. </div>
  9. <div class="side-menu side-menu--right">
  10. </div>
  11. <header class="header">
  12. <a href="#" class="open-left">open></a>
  13. </header>
  14. <div>
  15. PAGE CONTENT
  16. </div>
  17. </body>
  18.  
  19. ==================
  20. SASS:
  21.  
  22. $pushMenuWidth : 280px;
  23. .side-menu {
  24. position: fixed;
  25. top: 0;
  26. overflow: auto;
  27. width: $pushMenuWidth;
  28. height: 100%;
  29. z-index: 202;
  30. /* Vertical menu that slides from the left or right */
  31. &.side-menu--left {
  32. left: -$pushMenuWidth;
  33. transition: left 0.5s ease;
  34. .side-menu--left--open & {
  35. &.side-menu--left {
  36. left: 0;
  37. box-shadow: 1px 2px 4px rgba(0,0,0,.2);
  38. }
  39. }
  40. }
  41. &.side-menu--right {
  42. right: -$pushMenuWidth;
  43. transition: right 0.5s ease;
  44. .side-menu--right--open & {
  45. &.side-menu--right {
  46. right: 0;
  47. }
  48. }
  49. }
  50. }
  51.  
  52. ===============================
  53. JS:
  54.  
  55. YP.UserMenu = (function($) {
  56. var userMenu = {
  57. menuVar : {
  58. $body : $('body')
  59. },
  60.  
  61. _init: function () {
  62. userMenu._btnEvents('.open-left', 'side-menu--left--open');
  63. userMenu._btnEvents('.open-right', 'side-menu--right--open');
  64. userMenu._closeBtn();
  65. },
  66.  
  67. _btnEvents : function(selectorStr, toggleClass){
  68. $('.header').on('click', selectorStr, function(e){
  69. e.preventDefault();
  70. e.stopPropagation();
  71. userMenu.menuVar.$body.toggleClass(toggleClass);
  72. });
  73. },
  74.  
  75. _removeOpenClassBody: function(){
  76. userMenu.menuVar.$body.removeClass('side-menu--left--open side-menu--right--open');
  77. },
  78.  
  79. _closeBtn : function(){
  80. $('.side-menu').on('click', '.jsCloseUserMenu', function(e){
  81. e.preventDefault();
  82. userMenu._removeOpenClassBody();
  83. });
  84.  
  85. $('#overlayContainer').click(function(){
  86. userMenu._removeOpenClassBody();
  87. });
  88. }
  89. };
  90.  
  91. $(function() {
  92. userMenu._init();
  93. });
  94.  
  95. })($);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement