bil*_*noo 2 jquery menu jquery-plugins hide show-hide
我有这个插件,是从http://www.berriart.com/sidr/下载的,一旦我单击按钮,它就会显示菜单菜单,当我想关闭它时,只能通过单击同一按钮来关闭它。现在,我想在正文中的任意位置添加一个单击,以移回菜单。谁能帮我解决这个问题?
这是我的html:
<div id="sidr">
<!-- <button class="close-side-menu"><i class="icon-close"></i></button> -->
<ul>
<li>
</li>
</ul>
</div>
<button type="button" class="menu-icon open-side-menu">
<a id="simple-menu" href="#sidr">
</a>
</button>
<script>
$(document).ready(function() {
$('#simple-menu').sidr();
});
</script>
Run Code Online (Sandbox Code Playgroud)
试试这个脚本:
$(document).mouseup(function (e){
var container = $("#sidr");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
$.sidr('close', 'sidr');
}
});
Run Code Online (Sandbox Code Playgroud)
设法从此处获取脚本,然后能够添加,$.sidr('close', 'sidr');只需确保将'sidr'更改为您想要尝试的菜单的类名即可。
希望这可以帮助。