JAVASCRIPT 26
Javascript menu action By micha on 12th May 2020 04:20:26 PM
  1. /*
  2.  * Menu actions
  3.  */
  4. function mobile_menu(action) {
  5.  
  6.   if (action == 'close') {
  7.  
  8.     if ($('#page-header').hasClass('sticky')) {
  9.       $('nav.main-mn').fadeOut(400, function() {
  10.         $('#main-menu .mobile-logo').fadeIn(200);
  11.       });
  12.     } else {
  13.       $('nav.main-mn').fadeOut(400);
  14.     }
  15.     $('#mobile-menu').addClass('closed').removeClass('opened');
  16.  
  17.   } else if (action == 'open') {
  18.  
  19.     $('nav.main-mn').fadeIn(200, function () { });
  20.     if ($('#page-header').hasClass('sticky')) {
  21.       $('#main-menu .mobile-logo').hide();
  22.     }
  23.     $('#mobile-menu').addClass('opened').removeClass('closed');
  24.  
  25.   }
  26. }
  27.  
  28. /*
  29.  * Anchor jump animation
  30.  */
  31. function jumpToAnchor(target, offset, speed) {
  32.   offset = (typeof offset !== 'undefined') ?  offset : 0;
  33.   speed  = (typeof speed !== 'undefined') ?  speed : 1200;
  34.   jQuery('html, body').stop().animate({
  35.     scrollTop: jQuery(target).offset().top - offset
  36.   }, speed, 'easeInOutExpo');
  37.   console.log(target);
  38. }
  39.  
  40.  
  41. /*
  42.  * Menu click animation
  43.  */
  44.  $('a.anchor').click(function (event) {
  45.     let hash = $(this)[0].hash;
  46.     jumpToAnchor(hash, 100);
  47.     mobile_menu('close');
  48.     event.preventDefault();
  49.   });
  50.  
  51.   $('li.anchor-link a').click(function (event) {
  52.     let hash = $(this)[0].hash;
  53.     jumpToAnchor(hash, 100);
  54.     mobile_menu('close');
  55.     event.preventDefault();
  56.   });

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.