我使用的是SlickNav jQuery plugin,但默认情况下似乎没有设置模糊或丢失焦点时自动关闭菜单,也没有对其进行设置。
我认为这只是一个简单的调用,如下所示:
<script>
$(document).ready(function() {
//close menu on lost focus
$('.js .slicknav_menu').focusout(function(event){
$(this).slicknav('close');
});
});
</script>但这并不能做任何事情。在菜单外单击时如何关闭菜单?
发布于 2014-10-20 07:42:37
我引用了你在问题中提到的网站。尝试了站点中给出的第一个示例。(其HTML代码如下所示)
HTML -
<ul id="menu">
<li><a class="scroll" href="#features">Features</a></li>
<li><a class="scroll" href="#usage">Usage Instructions</a></li>
<li><a class="scroll" href="#examples">Examples</a></li>
<li><a href="http://github.com">View on Github</a></li>
</ul>我看到菜单在丢失焦点事件时默认不会关闭。下面的代码实现了同样的效果。
$(document).ready(function() {
//close menu on lost focus
$('.slicknav_menu').focusout(function(event){
$('#menu').slicknav('close'); //Here 'menu' is the id of ul.
});
});发布于 2016-02-04 22:57:53
我用的是这样的东西。
这也适用于手机。
$(window).on("touchstart", function(e) {
var container = $("#menu");
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
{
$('#menu').slicknav('close');
}
});https://stackoverflow.com/questions/26455899
复制相似问题