本文介绍了我单击菜单项后,jQuery移动菜单关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基于此演示: http://webdesignerwall.com/demo/mobile-nav/这是我的代码.
based on this demo: http://webdesignerwall.com/demo/mobile-nav/ this is my code.
<script type="text/javascript">
jQuery(document).ready(function($){
/* prepend menu icon */
$('#nav-wrap').prepend('<div id="menu-icon"><img id="logo" src="<?php echo site_url(); ?>/wp-content/themes/blue-and-grey/images/mobileimages/hme_btn.png" /></div>');
/* toggle nav */
$("#menu-icon").on("click", function(){
$("#nav").slideToggle();
$(this).toggleClass("active");
});
});
</script>
我需要的是单击菜单项后要关闭"的菜单,因为它是单页网站,并且我不希望单击后保持打开状态.我该怎么办?
what i need is the menu to "close" after i click a menu item because it's a single page website, and i don't want it to stay opened after i clicked. how do i do that?
非常感谢您!
推荐答案
添加一个额外的事件以使其发生.单击某些菜单项时,可以触发#menu-icon
的click
:
Add an extra event to make it happen. You could trigger the click
of #menu-icon
when some menu item is clicked:
$("#nav").on("click", "li", function () {
$("#menu-icon").click();
//or $("#nav").slideToggle();
});
演示: http://jsfiddle.net/hungerpain/RtMNj/2/
这篇关于我单击菜单项后,jQuery移动菜单关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!