jquery(document).ready(function($){ var $lateral_menu_trigger = $('#cd-menu-trigger'), $content_wrapper = $('.cd-main-content'), $navigation = $('.menup'); //open-close lateral menu clicking on the menu icon $lateral_menu_trigger.on('click', function(event){ event.preventdefault(); $lateral_menu_trigger.toggleclass('is-clicked'); $navigation.toggleclass('lateral-menu-is-open'); $content_wrapper.toggleclass('lateral-menu-is-open').one('webkittransitionend otransitionend otransitionend mstransitionend transitionend', function(){ // firefox transitions break when parent overflow is changed, so we need to wait for the end of the trasition to give the body an overflow hidden $('body').toggleclass('overflow-hidden'); }); $('#cd-lateral-nav').toggleclass('lateral-menu-is-open'); //check if transitions are not supported - i.e. in ie9 if($('html').hasclass('no-csstransitions')) { $('body').toggleclass('overflow-hidden'); } }); //点击空白区域,关闭菜单close lateral menu clicking outside the menu itself $content_wrapper.on('click', function(event){ if( !$(event.target).is('#cd-menu-trigger, #cd-menu-trigger span, #menup.lateral-menu-is-open') ) { $lateral_menu_trigger.removeclass('is-clicked'); $navigation.removeclass('lateral-menu-is-open'); $content_wrapper.removeclass('lateral-menu-is-open') .one('webkittransitionend otransitionend otransitionend mstransitionend transitionend', function(){ //$('body').removeclass('overflow-hidden'); }); $('#cd-lateral-nav').removeclass('lateral-menu-is-open'); //check if transitions are not supported if($('html').hasclass('no-csstransitions')) { //$('body').removeclass('overflow-hidden'); } } }); //open (or close) submenu items in the lateral menu. close all the other open submenu items. $('.item-has-children').children('a').on('click', function(event){ event.preventdefault(); $(this).toggleclass('submenu-open').next('.sub-menu').slidetoggle(200).end().parent('.item-has-children').siblings('.item-has-children').children('a').removeclass('submenu-open').next('.sub-menu').slideup(200); }); });