jQuery(function($){ $('#moveUp').on('click',function(event){ event.preventDefault(); $('html, body').animate({ scrollTop: 0 },500); }); jQuery('#off-canvas-toggle').on('click',function(event){ event.preventDefault(); jQuery('.off-canvas-wrap').toggleClass('active'); }); }); jQuery(function($){ var menu = $('#offcanvas .nav.menu'); var animationActive = false; $(window).resize(function(){ disableCanvas(); }); $('.switcherCanvas').click(function(){}); $('body').on('click' , ".switcherCanvas",function(){ canvasAction(); }); $('body').on('click' , ".offcanvasSwitch",function(){ canvasAction(); }); function canvasAction(){ if(!animationActive){ animationActive = true; canvasActive = $("#offcanvas").hasClass('active'); if(canvasActive){ disableCanvas(); }else{ activateCanvas(); } } } function disableCanvas(){ $('#offcanvas').animate({left : '-250px'},500, function(){ animationActive = false; }).removeClass('active'); $( '#containerContent' ).animate({opacity : '1'},500).removeClass( 'switcherCanvas' ); $( '#offcanvas .openSubMenu' ).removeClass( 'openSubMenu' ); } function activateCanvas(){ $('#offcanvas').animate({'left' : '0'},500, function(){ animationActive = false; }).addClass('active'); $( '#containerContent' ).animate( { opacity : '0.3' } , 500 ).addClass( 'switcherCanvas' ); } /* menu offcanvas*/ $( 'li.parent a ,li.parent span' , menu).click(function(e){ li = $(this).closest('li'); $(this).unbind('hover'); if( !$(li).hasClass('openSubMenu') && $(li).hasClass('parent') ){ e.preventDefault(); ulParent = $( this ).closest('ul'); $( '.openSubMenu' , ulParent).removeClass( 'openSubMenu' ); $(li).addClass('openSubMenu'); } }); });