导航菜单

HTML5各种svg元素炫酷弹性动画特效

阿里云


这是一款极具创意的 HTML5 各种 svg 元素炫酷弹性动画特效。该 svg 特效共集成了 9 种效果,每种效果都是以弹性动画为基础,将各种 svg 元素制作为像弹簧一样具有弹性,效果非常震撼。

section

下面是侧边栏弹性动画的 demo 的 html 结构:

也想出现在这里?联系我们
创客主机
  1. <nav id="menu" class="menu">
  2.     <button class="menu__handle"><span>Menu</span></button>
  3.     <div class="menu__inner">
  4.         <ul>
  5.             <li><a href="#"><i class="fa fa-fw fa-home"></i><span>Home<span></a></li>
  6.             <li><a href="#"><i class="fa fa-fw fa-heart"></i><span>Favs<span></a></li>
  7.             <li><a href="#"><i class="fa fa-fw fa-folder"></i><span>Files<span></a></li>
  8.             <li><a href="#"><i class="fa fa-fw fa-tachometer"></i><span>Stats<span></a></li>
  9.         </ul>
  10.     </div>
  11.     <div class="morph-shape" data-morph-open="M300-10c0,0,295,164,295,410c0,232-295,410-295,410" data-morph-close="M300-10C300-10,5,154,5,400c0,232,295,410,295,410">
  12.         <svg width="100%" height="100%" viewBox="0 0 600 800" preserveAspectRatio="none">
  13.             <path fill="none" d="M300-10c0,0,0,164,0,410c0,232,0,410,0,410"/>
  14.         </svg>
  15.     </div>
  16. </nav>

SVG 被插入到内部菜单中,我们使用两个 data attributes 来存储路径信息。

SVG 应该被放到菜单里面,并且保证在移动菜单两条边时有足够的空间使线条不被切断。注意:SVG 通过设置宽和高 100%来使其具有响应性。

  1. .morph-shape {
  2.     position: absolute;
  3.     width: 240px;
  4.     height: 100%;
  5.     top: 0;
  6.     right: 0;
  7. }
  8.  
  9. .morph-shape svg path {
  10.     stroke: #5f656f;
  11.     stroke-width: 5px;
  12. }

section

通过 Snap.svg 我们可以讲 svg 从一种形状变为另一种形状:

  1. (function() {
  2.  
  3.     function SVGMenu( el, options ) {
  4.         this.el = el;
  5.         this.init();
  6.     }
  7.  
  8.     SVGMenu.prototype.init = function() {
  9.         this.trigger = this.el.querySelector( 'button.menu__handle' );
  10.         this.shapeEl = this.el.querySelector( 'div.morph-shape' );
  11.  
  12.         var s = Snap( this.shapeEl.querySelector( 'svg' ) );
  13.         this.pathEl = s.select( 'path' );
  14.         this.paths = {
  15.             reset : this.pathEl.attr( 'd' ),
  16.             open : this.shapeEl.getAttribute( 'data-morph-open' ),
  17.             close : this.shapeEl.getAttribute( 'data-morph-close' )
  18.         };
  19.  
  20.         this.isOpen = false;
  21.  
  22.         this.initEvents();
  23.     };
  24.  
  25.     SVGMenu.prototype.initEvents = function() {
  26.         this.trigger.addEventListener( 'click', this.toggle.bind(this) );
  27.     };
  28.  
  29.     SVGMenu.prototype.toggle = function() {
  30.         var self = this;
  31.  
  32.         if( this.isOpen ) {
  33.             classie.remove( self.el, 'menu--anim' );
  34.             setTimeout( function() { classie.remove( self.el, 'menu--open' );   }, 250 );
  35.         }
  36.         else {
  37.             classie.add( self.el, 'menu--anim' );
  38.             setTimeout( function() { classie.add( self.el, 'menu--open' );  }, 250 );
  39.         }
  40.         this.pathEl.stop().animate( { 'path' : this.isOpen ? this.paths.close : this.paths.open }, 350, mina.easeout, function() {
  41.             self.pathEl.stop().animate( { 'path' : self.paths.reset }, 800, mina.elastic );
  42.         } );
  43.  
  44.         this.isOpen = !this.isOpen;
  45.     };
  46.  
  47.     new SVGMenu( document.getElementById( 'menu' ) );
  48.  
  49. })();

HTML5 各种 svg 元素炫酷弹性动画特效

已有 251 人购买
  • lwfr
查看演示升级 VIP立刻购买

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

发表回复

热销模板

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

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