【发布时间】:2015-07-08 09:31:44
【问题描述】:
我正在使用 mmenu.js 制作我的菜单,以便在宽屏上打开并在中型到移动设备上关闭时打开。但我也希望在宽屏上能够使用切换按钮将其关闭。
目前,您只能在移动设备上关闭它。
这是fiddle
$(function() {
var $menu = $('nav#menu'),
$html = $('html, body');
$menu.mmenu({
extensions: ["widescreen", "theme-dark"]
});
var $anchor = false;
$menu.find( 'li > a' ).on(
'click',
function( e )
{
$anchor = $(this);
}
);
var api = $menu.data( 'mmenu' );
api.bind( 'closed',
function()
{
if ( $anchor )
{
var href = $anchor.attr( 'href' );
$anchor = false;
// if the clicked link is linked to an anchor, scroll the page to that anchor
if ( href.slice( 0, 1 ) == '#' )
{
$html.animate({
scrollTop: $( href ).offset().top
});
}
}
}
);
});
【问题讨论】:
标签: javascript jquery mmenu