导航菜单

动画特效下拉导航菜单

阿里云

这是一款仿 stripe.com 网站的带变形动画特效的下拉导航菜单特效。该导航菜单在菜单项之间切换时,下拉菜单会根据菜单内容的大小来动态变形,效果非常有趣。

HTML 结构:

该导航菜单的 HTML 结构如下:

也想出现在这里?联系我们
创客主机
  1. <header class="cd-morph-dropdown">
  2.   <a href="#0" class="nav-trigger">Open Nav<span aria-hidden="true"></span></a>
  3.  
  4.   <nav class="main-nav">
  5.     <ul>
  6.       <li class="has-dropdown gallery" data-content="about">
  7.         <a href="#0">About</a>
  8.       </li>
  9.  
  10.       <li class="has-dropdown links" data-content="pricing">
  11.         <a href="#0">Pricing</a>
  12.       </li>
  13.  
  14.       <li class="has-dropdown button" data-content="contact">
  15.         <a href="#0">Contact</a>
  16.       </li>
  17.     </ul>
  18.   </nav>
  19.  
  20.   <div class="morph-dropdown-wrapper">
  21.     <div class="dropdown-list">
  22.       <ul>
  23.         <li id="about" class="dropdown gallery">
  24.           <!-- dropdown content here -->
  25.         </li>
  26.  
  27.         <li id="pricing" class="dropdown links">
  28.           <!-- dropdown content here -->
  29.         </li>
  30.  
  31.         <li id="contact" class="dropdown button">
  32.           <!-- dropdown content here -->
  33.         </li>
  34.       </ul>
  35.  
  36.       <div class="bg-layer" aria-hidden="true"></div>
  37.     </div> <!-- dropdown-list -->
  38.   </div> <!-- morph-dropdown-wrapper -->
  39. </header>

初始化插件:

为了实现这个导航菜单,特效中创建了一个 morphDropdown 对象。并使用 bindEvents ()方法来处理元素的事件。

  1. function morphDropdown( element ) {
  2.   this.element = element;
  3.   this.mainNavigation = this.element.find('.main-nav');
  4.   this.mainNavigationItems = this.mainNavigation.find('.has-dropdown');
  5.   this.dropdownList = this.element.find('.dropdown-list');
  6.   //...
  7.  
  8.   this.bindEvents();
  9. }

bindEvents()方法用于在.has-dropdown 和.dropdown 元素上检测鼠标进入和鼠标离开事件。

  1. morphDropdown.prototype.bindEvents = function() {
  2.   var self = this;
  3.  
  4.   this.mainNavigationItems.mouseenter(function(event){
  5.     //hover over one of the nav items -> show dropdown
  6.     self.showDropdown($(this));
  7.   }).mouseleave(function(){
  8.     //if not hovering over a nav item or a dropdown -> hide dropdown
  9.     if( self.mainNavigation.find('.has-dropdown:hover').length == 0 && self.element.find('.dropdown-list:hover').length == 0 ) self.hideDropdown();
  10.   });
  11.  
  12.   //...
  13. };                  
  14.  
  15. showDropdown方法用于处理宽度、高度和.dropdown-list元素的translateX值,以及放大和缩小.bg-layer元素。
  16. morphDropdown.prototype.showDropdown = function(item) {
  17.   var selectedDropdown = this.dropdownList.find('#'+item.data('content')),
  18.     selectedDropdownHeight = selectedDropdown.innerHeight(),
  19.     selectedDropdownWidth = selectedDropdown.children('.content').innerWidth(),
  20.     selectedDropdownLeft = item.offset().left + item.innerWidth()/2 - selectedDropdownWidth/2;
  21.  
  22.   //update dropdown and dropdown background position and size
  23.   this.updateDropdown(selectedDropdown, parseInt(selectedDropdownHeight), selectedDropdownWidth, parseInt(selectedDropdownLeft));
  24.  
  25.   //add the .active class to the selected .dropdown and .is-dropdown-visible to the .cd-morph-dropdown 
  26.   //...
  27. };
  28.  
  29. morphDropdown.prototype.updateDropdown = function(dropdownItem, height, width, left) {
  30.   this.dropdownList.css({
  31.       '-moz-transform': 'translateX(' + left + 'px)',
  32.       '-webkit-transform': 'translateX(' + left + 'px)',
  33.     '-ms-transform': 'translateX(' + left + 'px)',
  34.     '-o-transform': 'translateX(' + left + 'px)',
  35.     'transform': 'translateX(' + left + 'px)',
  36.     'width': width+'px',
  37.     'height': height+'px'
  38.   });
  39.  
  40.   this.dropdownBg.css({
  41.     '-moz-transform': 'scaleX(' + width + ') scaleY(' + height + ')',
  42.       '-webkit-transform': 'scaleX(' + width + ') scaleY(' + height + ')',
  43.     '-ms-transform': 'scaleX(' + width + ') scaleY(' + height + ')',
  44.     '-o-transform': 'scaleX(' + width + ') scaleY(' + height + ')',
  45.     'transform': 'scaleX(' + width + ') scaleY(' + height + ')'
  46.   });
  47. };

动画特效下拉导航菜单

已有 418 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!