我正在尝试将子菜单替换为nav-flitch节中的子菜单。
此javascript可以运行,但是由于我只想更改该部分中的类而中断了桌面版本子菜单。
<section class="nav-flitch">
<nav class="nav hide-me">
<?php wp_nav_menu( array( 'theme_location' => 'mobile-menu', 'menu' ) ); ?>
</nav>
</section>
<script>
;(function($) {
// DOM ready
$(function() {
// Append the mobile icon nav
$('.nav').append($('<div class="nav-mobile"></div>'));
// Add a <span> to every .menu-item that has a <ul> inside
$('.menu-item').has('ul').prepend('<span class="nav-click"><i class="nav-
arrow"></i></span>');
// Click to reveal the nav
$('.nav-mobile').click(function(){
$('.menu').toggle();
});
// Dynamic binding to on 'click'
$('.menu').on('click', '.nav-click', function(){
// Toggle the nested nav
$(this).siblings('.submenu').toggle();
// Toggle the arrow using CSS3 transforms
$(this).children('.nav-arrow').toggleClass('nav-rotate');
});
});
})(jQuery);
</script>
function change_submenu_class($menu) {
$menu = preg_replace('/ class="sub-menu"/','/ class="submenu" /',$menu);
return $menu;
}
add_filter('wp_nav_menu','change_submenu_class');