RUSSEL86

Mobile menu custom

Nov 10th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. html for responsive menu
  2. ---------------
  3. <div id="header_mobile" class="for_mobile">
  4. <div class="mobile_head_area">
  5. <div class="head_navber_mainwrapper">
  6. <div id="toggle_menu_icon" class="head_navber">
  7. <img class="menu_icon" src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon-bar.png" alt="" /> <span>MENU</span>
  8. </div>
  9. <div class="mobile_menu_area">
  10. <div class="mobile_menu_head">
  11. <div class="mobile_middle_head">
  12. MENU
  13. </div>
  14. <div class="mobile_menu_closebar">
  15. <img class="menu_close" src="<?php echo get_stylesheet_directory_uri(); ?>/img/close.png" alt="" />
  16. </div>
  17. </div>
  18. <div class="mobile_menu_itewrap">
  19. <div class="mobile_menu_items">
  20. <?php wp_nav_menu(
  21. array(
  22. 'theme_location' => 'menu-mobile',
  23. 'container' => 'nav',
  24. 'container_class' => 'upper-mobilenav',
  25. 'menu_class' => 'nav_for_mobile',
  26. 'menu_id' => 'nav_mobil',
  27. ) );?>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. <div class="mobile_logo_head">
  33. <a href="<?php bloginfo('url'); ?>"><img src="<?php the_field('mobile_main_logo', 'option'); ?>" alt="<?php echo esc_attr(get_bloginfo('name')); ?>" id="logo_mobile"/></a>
  34. </div>
  35. </div>
  36. </div>
  37.  
  38. /*mobile menu style*/
  39. .head_navber_mainwrapper {
  40. float: left;
  41. width: 100%;
  42. padding: 10px 0;
  43. background: #ffb600;
  44. }
  45. div#toggle_menu_icon {
  46. color: #222;
  47. font-weight: bold;
  48. font-size: 20px;
  49. line-height: 17px;
  50. width: 120px;
  51. margin-top: 6px;
  52. cursor: pointer;
  53. margin: 0 auto;
  54. }
  55. img.menu_icon {
  56. float: left;
  57. margin-right: 3px;
  58. display: block;
  59. }
  60. .mobile_menu_area {
  61. position: fixed;
  62. top: 0;
  63. left: -110%;
  64. z-index: 9999;
  65. background: #fff;
  66. width: 100%;
  67. transition: all 0.4s;
  68. padding: 5px 0;
  69. height: 100vh;
  70. }
  71. .mobile_menu_head {
  72. padding: 10px 0px;
  73. border-bottom: 1px solid #152877;
  74. position: relative;
  75. }
  76. .mobile_middle_head {
  77. font-size: 16px;
  78. font-weight: 700;
  79. color: #222;
  80. text-align: center;
  81. }
  82. .mobile_menu_closebar {
  83. position: absolute;
  84. right: 15px;
  85. top: 12px;
  86. cursor: pointer;
  87. }
  88. img.menu_close {
  89. width: 20px;
  90. display: block;
  91. position: relative;
  92. top: -6px;
  93. }
  94. .mobile_menu_items {
  95. padding: 5px 0px 5px;
  96. }
  97. .mobile_logo_head {
  98. width: 270px;
  99. margin: 0 auto;
  100. }
  101.  
  102. ul#nav_mobil>li {
  103. text-align: left;
  104. }
  105. ul#nav_mobil>li.menu-item-has-children {
  106. position: relative;
  107. }
  108. ul#nav_mobil>li.menu-item-has-children:before {
  109. content: "";
  110. height: 100%;
  111. width: 1px;
  112. background: #222;
  113. right: 45px;
  114. position: absolute;
  115. top: 0;
  116. }
  117. ul#nav_mobil>li>a {
  118. color: #8a181b;
  119. display: block;
  120. font-size: 16px;
  121. border-bottom: 1px solid #222;
  122. padding: 8px 15px;
  123. position: relative;
  124. }
  125.  
  126. ul#nav_mobil>li ul.sub-menu li a {
  127. font-size: 14px;
  128. display: block;
  129. padding: 8px 15px;
  130. color: #8a181b;
  131. border-bottom: 1px solid #222;
  132. }
  133. ul#nav_mobil>li.menu-item-has-children > a:before {
  134. content: "\f067";
  135. position: absolute;
  136. right: 18px;
  137. font-family: fontawesome;
  138. }
  139. ul#nav_mobil>li.menu-item-has-children > a:after{}
  140. ul#nav_mobil>li ul.sub-menu {
  141. display: none;
  142. }
  143. .mobile_menu_area.expand {
  144. left: 0;
  145. }
  146. ul#nav_mobil>li.menu-item-has-children > a.icon:before {
  147. content: "\f068";
  148. }
  149.  
  150.  
  151.  
  152.  
  153. jQuery for responsive menu
  154. ---------------
  155. $(".head_navber").click(function(){
  156. $(".mobile_menu_area").toggleClass("expand");
  157. });
  158. $(".mobile_menu_closebar").click(function(){
  159. $(".mobile_menu_area").removeClass("expand");
  160. });
  161. $("ul#nav_mobil>li.menu-item-has-children > a").click(function(e){
  162. e.preventDefault();
  163. $(this).toggleClass("icon");
  164. $(this).next('ul.sub-menu').slideToggle();
  165. });
  166.  
  167. var newWindowWidth = $(window).width();
  168. if (newWindowWidth < 767) {
  169. $("ul.sub-menu > li:first-child").each(function(){
  170. var parent = $(this).parent('ul').parent('.menu-item-has-children');
  171. var copy = parent.clone();
  172. $(copy).removeClass("menu-item-has-children").find(".sub-menu").remove();
  173. $(this).before(copy);
  174. });
  175. $('.menu-item-has-children > a').attr('href' ,'#');
  176. }
Advertisement
Add Comment
Please, Sign In to add comment