Giter VIP home page Giter VIP logo

svg-morpheus's Introduction

SVG Morpheus

JavaScript library enabling SVG icons to morph from one to the other. It implements Material Design's Delightful Details transitions.

Live demo

Launch Live Demo

Installing

Download

You have two options to get the library:

  • Download SVG Morpheus from GitHub.
  • Use Bower to download the library. Just run bower install svg-morpheus in the directory you want to download the files to.

Add Script

Simply add the svg-morpheus.js script to your website/application. No other scripts are needed. Both the minified and uncompressed (for development) versions are in the /compile folder.

<script src="svg-morpheus.js"></script>

Usage

  1. Add an icon set SVG to the HTML file where you want to show the morphing icon.
  2. Create a SVG Morpheus instance for the icon set by calling new SVGMorpheus(element). Object/IFrame/Inline SVG element containing the icon set. Can be a DOM element or a CSS query selector.. For example:
var myIcons = new SVGMorpheus('#myIconSet');
  1. After initializing, you get a SVGMorpheus object having to(ID) function. ID is an id of Icon in the icon set. Use it to morph the icon to another icon in the icon set.
myIcons.to('icon1');

Options

SVGMorpheus Constructor

var myIcons = new SVGMorpheus(element, options, callback);

element - Object/IFrame/SVG element containing an icon set. Can be a DOM element or a CSS query selector.

options - Optional. Object specifying default options.

options.iconId - Optional. Id of an icon shown after initialization. Default: last icon in the icon set.

options.duration - Optional. Set a default duration for transition animations, in msec. Default: 750.

options.easing - Optional. Set a default easing for transition animations. Default: quad-in-out.

options.rotation - Optional. Set a default rotation for icon shapes. clock = clockwise, counterclock = counterclockwise, random = randomly set clock/counterclock, none = no rotation. Default: clock.

callback - Optional. Set a default callback function to call at the animation end.

SVGMorpheus.to()

myIcons.to(iconId, options, callback);

iconId - Id of an icon to transition to.

options - Optional. Object specifying the animation options.

options.duration - Optional. Set a duration for the animation, in msec.

options.easing - Optional. Set an easing for the animation.

options.rotation - Optional. Set a rotation for icon shapes. clock = clockwise, counterclock = counterclockwise, random = randomly set clock/counterclock, none = no rotation.

callback - Optional. Set a callback function to call at the animation end.

Supported Easings

circ-in, circ-out, circ-in-out, cubic-in, cubic-out, cubic-in-out, elastic-in, elastic-out, elastic-in-out, expo-in, expo-out, expo-in-out, linear, quad-in, quad-out, quad-in-out, quart-in, quart-out, quart-in-out, quint-in, quint-out, quint-in-out, sine-in, sine-out, sine-in-out

Icon Set structure

SVG should have the following structure to be a valid icon set:

  • 1st tier nodes are <g> elements having 'id' attribute. They define icons in the icon set.
  • 2nd tier nodes are shape elements (<path>, circle, rect, ellipse, polygon, line). They define the icon graphics.
<svg>
  <g id="icon1">
    Shape elements
  </g>
  <g id="icon2">
    Shape elements
  </g>
</svg>

Example code

Check the Demos directory for examples.

Supported browsers

Chrome Firefox IE >= 10 Safari Opera iOS Safari Android Browser >= 4.4 Chrome for Android

License

See the LICENSE file.

svg-morpheus's People

Contributors

alexk111 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.