php 使用Velocity.js的NavMenu下拉菜单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用Velocity.js的NavMenu下拉菜单相关的知识,希望对你有一定的参考价值。

var menuToggleOnClick = function() {
  var toggle = $(this);
  var subMenu = toggle.next('ul.sub-menu');

  if (toggle.hasClass('ion-chevron-down')) {
    subMenu.velocity('slideDown', {
      duration: 400
    });
    toggle.toggleClass('ion-chevron-down ion-chevron-up');
    $(this).parent('.menu-item-has-children').toggleClass('hover');
  } else if (toggle.hasClass('ion-chevron-up')) {
    subMenu.velocity('slideUp', {
      duration: 400
    });
    toggle.toggleClass('ion-chevron-down ion-chevron-up');
    $(this).parent('.menu-item-has-children').toggleClass('hover');
  }
};

var menuToggleOnHover = function() {
  var toggle = $(this).find('i');
  var subMenu = $(this).find('ul.sub-menu');

  if (toggle.hasClass('ion-chevron-down')) {
    subMenu.velocity('slideDown', {
      duration: 400
    });
    toggle.toggleClass('ion-chevron-down ion-chevron-up');
    $(this).toggleClass('hover');
  }
};

var menuToggleOffHover = function() {
  var toggle = $(this).find('i');
  var subMenu = $(this).find('ul.sub-menu');

  if ($(this).hasClass('hover')) {
    subMenu.velocity('slideUp', {
      duration: 400
    });
    toggle.toggleClass('ion-chevron-down ion-chevron-up');
    $(this).toggleClass('hover');
  }
};

$('.menu-item-has-children i').on('click', menuToggleOnClick);

$('.menu-item-has-children').hover(menuToggleOnHover, menuToggleOffHover);
/*** HIDE ICON BUT SHOW FOR MENU ITEMS WITH CHILDREN ***/
li {
  i.ion {
    display: none;
  }
  
  &.menu-item-has-children {
    > i.ion, > a {
      display: inline-block;
    }

    > i.ion {
      padding-left: 5px;
    }
  }
}
/*** ADD DOWN ARROW ICON TO AFTER PROPERTY ***/
function scratch_main_nav() {
  // display the wp3 menu if available
  wp_nav_menu(array(
    'container' => false, // remove nav container
    'container_class' => '', // class of container (should you choose to use it)
    'menu' => __( 'Main Nav', 'scratch' ), // nav name
    'menu_class' => 'nav main-nav', // adding custom nav class
    'theme_location' => 'main-nav', // where it's located in the theme
    'before' => '', // before the menu
    'after' => '<i class="ion ion-chevron-down"></i>', // after the menu
    'link_before' => '', // before each link
    'link_after' => '', // after each link
    'depth' => 0    // fallback function
  ));
} /* end scratch main nav */

以上是关于php 使用Velocity.js的NavMenu下拉菜单的主要内容,如果未能解决你的问题,请参考以下文章

vue里面使用Velocity.js

如何在悬停中使用velocity.js?

利用velocity.js将svg动起来

为 CSS/JS/jQuery 动画使用 Velocity.js 或 Transit.js?

javascript动画:velocity.js学习

使用 Velocity.js 从 URL 渲染 SVG 动画