Giter VIP home page Giter VIP logo

vivus's Introduction

vivus.js

Demo available on http://maxwellito.github.io/vivus

Play with it on Vivus Instant

Vivus is a lightweight JavaScript class (with no dependencies) that allows you to animate SVGs, giving them the appearance of being drawn. There are a variety of different animations available, as well as the option to create a custom script to draw your SVG in whatever way you like.

Available via:

Join the conversation on Gitter

Try Vivus with your SVG on Vivus Instant. If you plan to use the library to animate a single SVG without callback or controls, this will allow you to download your animated SVG, powered by CSS, JavaScript free.

Animations

On the following images, the pink color represents the duration value, and the blue one is for delay value.

Delayed

Timeline for delayed animation

Every path element is drawn at the same time with a small delay at the start. This is currently the default animation.

Sync

Timeline for sync animation

Each line is drawn synchronously. They all start and finish at the same time, hence the name sync.

OneByOne

Timeline for oneByOne animation

Each path element is drawn one after the other. This animation gives the best impression of live drawing. The duration for each line depends on their length to make a constant drawing speed.

Principles

To get this effect, the script uses the CSS property strokeDashoffset. This property manages the stroke offset on every line of the SVG. Now, all we have to do is add some JavaScript to update this value progressively and the magic begins.

However, there's a problem with this. The strokeDashoffset property is only available on the path elements. This is an issue because in an SVG there are a lot of elements such as circle, rect, line and polyline which will break the animation. So to fix this, there is another class available in the repo called pathformer. It's made for transforming all objects of your SVG into path elements to be able to use strokeDashoffset and animate your SVGs.

The animation always draws elements in the same order as they are defined in the SVG tag.

There are few conditions that your SVG must meet:

  • All elements must have a stroke property and cannot be filled. This is because the animation only looks to progressively draw strokes and will not check for filled colours. For example: fill: "none"; stroke: "#FFF";

  • You should avoid creating any hidden path elements in your SVG. Vivus considers them all eligible to be animated, so it is advised to remove them before playing with it. If they are not removed the animation might not achieve the desired effect, with blank areas and gaps appearing.

  • text elements aren't allowed, they cannot be transformed into path elements. See #22 for more details.

The code is inspired from other repositories. The drawer is inspired from the excellent Codrops about the post SVG Drawing Animation (if you don't know this website, get ready to have your mind blown). Then for the pathformer, there is a lot of work from SVGPathConverter by Waest.

Usage

As I said, no dependencies here. All you need to do is include the scripts.

Inline SVG

<svg id="my-svg">
  <path...>
  <path...>
  <path...>
</svg>

<script>
  new Vivus('my-svg', {duration: 200}, myCallback);
</script>

Dynamic load

<object id="my-svg" type="image/svg+xml" data="link/to/my.svg"></object>

<script>
  new Vivus('my-svg', { duration: 200 }, myCallback);
</script>

or

<div id="my-div"></div>

<script>
  new Vivus('my-div', { duration: 200, file: 'link/to/my.svg' }, myCallback);
</script>

By default the object created will take the size of the parent element, this one must have a height and width or your SVG might not appear.

If you need to edit this object, it is accessible in the onReady callback:

new Vivus('my-div-id', {
  file: 'link/to/my.svg',
  onReady: function (myVivus) {
    // `el` property is the SVG element
    myVivus.el.setAttribute('height', 'auto');
  }
});

Check out the hacks page for more tricks.

Constructor

The Vivus constructor asks for 3 parameters:

  • ID (or object) of DOM element to interact with.
    It can be an inline SVG or a wrapper element to append an object tag from the option file
  • Option object (described in the following |
  • Callback to call at the end of the animation (optional)

Option list

Name Type Description
type string Defines what kind of animation will be used: delayed, sync, oneByOne, script, scenario or scenario-sync. [Default: delayed]
file string Link to the SVG to animate. If set, Vivus will create an object tag and append it to the DOM element given to the constructor. Be careful, use the onReady callback before playing with the Vivus instance.
start string Defines how to trigger the animation (inViewport once the SVG is in the viewport, manual gives you the freedom to call draw method to start, autostart makes it start right now). [Default: inViewport]
duration integer Animation duration, in frames. [Default: 200]
delay integer Time between the drawing of first and last path, in frames (only for delayed animations).
onReady function Function called when the instance is ready to play.
pathTimingFunction function Timing animation function for each path element of the SVG. Check the timing function part.
animTimingFunction function Timing animation function for the complete SVG. Check the timing function part.
dashGap integer Whitespace extra margin between dashes. Increase it in case of glitches at the initial state of the animation. [Default: 2]
forceRender boolean Force the browser to re-render all updated path items. By default, the value is true on IE only. (check the 'troubleshoot' section for more details).
reverseStack boolean Reverse the order of execution. The default behaviour is to render from the first 'path' in the SVG to the last one. This option allow you to reverse the order. [Default: false]
selfDestroy boolean Removes all extra styling on the SVG, and leaves it as original.

Methods

Name Description
play(speed, callback) Plays the animation with the speed given in parameter. This value can be negative to go backward, between 0 and 1 to go slowly, >1 to go faster, or <0 to go in reverse from current state. [Default: 1]. Callback executed after the animation is finished (optional)
stop() Stops the animation.
reset() Reinitialises the SVG to the original state: undrawn.
finish() Set the SVG to the final state: drawn.
setFrameProgress(progress) Set the progress of the animation. Progress must be a number between 0 and 1.
getStatus() Get the status of the animation between start, progress, end
destroy() Reset the SVG but make the instance out of order.

These methods return the object so you can chain the actions.

const myVivus = new Vivus('my-svg-id');
myVivus.stop().reset().play(2);

Play method callback

Instead of using the global constructor callback when you create the Vivus object, you can add callbacks to be executed for specific play method calls.

const myVivus = new Vivus('my-svg-id');
myVivus.play(1, function () {
  // called after the animation completes
});

// alternativly if you leave the speed param blank and use the default, you
// can pass the callback as the first parameter like so.
myVivus.play(function () {
  // called after the animation completes
});

Timing function

To give more freedom, it's possible to override the animation of each path and/or the entire SVG. It works a bit like the CSS animation timing function. But instead of using a cubic-bezier function, it use a simple JavaScript function. It must accept a number as parameter (between 0 to 1), then return a number (also between 0 and 1). It's a hook.

If you don't want to create your own, timing methods are available via the constructor object: EASE, EASE_IN, EASE_OUT and EASE_OUT_BOUNCE. Then set it in the option object to enjoy them.

// Here, the ease animation will be use for the global drawing.
new Vivus(
  'my-svg-id',
  {
    type: 'delayed',
    duration: 200,
    animTimingFunction: Vivus.EASE
  },
  myCallback
);

WARNING: animTimingFunction is called at every frame of the animation, and pathTimingFunction is also called at every frame for each path of your SVG. So be careful about them. Keep it simple, or it can affect the performance.

Extra attributes

The attribute data-ignore allows you to ignore path tags from the vivus animation.

<svg id="my-svg">
  <path...>
  <path data-ignore="true" ...>
  <path...>
</svg>

In this case, the second path won't be part of the animation.

Scenarize

This feature allows you to script the animation of your SVG. For this, the custom values will be set directly in the DOM of the SVG.

scenario

This type is easier to understand, but longer to implement. You just have to define the start and duration of each element with data-start and data-duration attributes. If it is missing, it will use the default value given to the constructor. The best part of this type is the flexibility it provides. You don't have to respect the order/stack of the SVG and you can start with the last element, then continue with the first to finish with all the rest at the same time.

You will then have to define custom rules for each element in your SVG via extra attributes in your SVG DOM :

  • data-start (integer) time when the animation must start, in frames
  • data-duration (integer) animation duration of this path, in frames
<svg>
  <path data-start="0" data-duration="10" ... />
  <path data-start="20" data-duration="10" ... />
  <path data-start="20" data-duration="20" ... />
  <path data-start="0" data-duration="30" ... />
</svg>

scenario-sync

It's not the sexiest code ever, but it's quite flexible. In addition to this, the behaviour is fairly different. By using this animation type, the default behaviour is the same as oneByOne. However, you can define some properties on a specific path item such as the duration, the delay to start (from the end of the previous path) and if it should be played synchronously.

  • data-delay (integer) time between the end of the animation of the previous path and the start of the current path, in frames
  • data-duration (integer) duration of this path animation, in frames
  • data-async (no value required) make the drawing of this path asynchronous. It means the next path will start at the same time. If a path does not have an attribute for duration or delay then the default values, set in the options, will be used.

Example: here is a simple SVG containing 5 elements. With the following options {duration: 20, delay: 0}, we should get this timeline

Timeline for script animation by default

This looks like 'oneByOne' animation, synchronous mode. But to make it a bit custom, here is what I can do:

<svg>
  <path data-duration="10" ... />
  <path data-delay="10" data-async ... />
  <path data-delay="15" ... />
  <path data-duration="10" data-delay="45" data-async ... />
  <path data-duration="50" data-delay="5" ... />
</svg>

This scenario should give us

Timeline for this custom script animation

I'm sorry if it does not look very sexy, and it's not really easy to use. I'm happy to make any changes, as long as the idea sounds interesting. Post an issue and I'll be very happy to talk about it!

Non Scaling

Some SVG elements might use non scaling properties such as vector-effect="non-scaling-stroke", which requires some additional custom logic. On instance construction Vivus will map all the child elements in the SVG and calculate their line length. If the element is resized during the animation, the calculated stroke style properties become invalid and the SVG will display incorrectly.

To keep animation consistency, the method recalc should be called when the SVG is resized. It will re-calculate the line length on affected child elements on the next frame calculation.

Code example:

// Create your Vivus instance
const vivusObject = new Vivus('my-div', {
  duration: 200,
  file: 'link/to/my.svg',
});

// Create your observer and set up a callback on resize
const resizeObserver = new ResizeObserver((entries) => {
  // Recalculate the line lengths
  vivusObject.recalc();
});

resizeObserver.observe(vivusObject.el);

Vivus will provide a warning in the console when it detects stroke scaling.

Development

To make it simpler a gulp file is set up to automise minifying, JShint and tests. If you have never used Gulp before this is a good opportunity. To use it, you need to install NodeJS first then run sudo npm install -g gulp.

To start, you will need to install the repo dependencies:

$ npm install

Then you can use NPM scripts to run the following tasks:

  • build make the build (generate dist/vivus.js and dist/vivus.min.js)
  • lint run ESlint on the source files
  • test run Karma

Troubleshoot

Internet Explorer

Some SVG weren't working at all. The only solution found was to clone and replace each updated path element. Of course this solution requires more resources and a lot of DOM manipulation, but it will give a smooth animation like other browsers. This fallback is only applied on Internet Explorer (all versions), and can be disabled via the option forceRender.

Replacing each updated path by a clone was the only way to force IE to re-render the SVG. On some SVGs this trick is not necessary, but IE can be a bit tricky with this. If you're worried about performance, I would recommend checking if your SVG works correctly by disabling the forceRender option. If it works correctly on IE, then keep it like this.

By default, forceRender is true on Internet Explorer only.

Firefox

For Firefox users, you might encounter some glitches depending on your SVG and browser version. On versions before 36, there is a problem retrieving path length via getTotalLength method. Returning 174321516544 instead of 209 (I'm not exaggerating, this comes from a real case), messing up the entire animation treatment. Unfortunately, there's nothing that this library can do, this is due to Firefox. I hope to find a workaround, but at the moment I can only recommend that you test your animation on previous versions of Firefox.

Debug

For an easier debug have a look to the attribute map of your Vivus object. This contains the mapping of your animation. If you're using a modern browser, I recommend console.table to get a nice output of the array which will make your debug easier.

const logo = new Vivus('myLogo', { type: 'scenario-sync' });

// The property 'map' contain all the SVG mapping
console.table(logo.map);

Special thanks!

Thanks to all contributors! Also users who pushed me to improve the library by publishing it on NPM, or browser compatibility or features. Also thanks for fixing my awful english :)

and many others...

vivus's People

Contributors

a2 avatar afc163 avatar alexgurr avatar dandv avatar evaferreira avatar fay-jai avatar fejes713 avatar flyingfisch avatar hayveno avatar ibmua avatar jsimnz avatar kendrick-k avatar lukasdrgon avatar maxwellito avatar melashkov avatar muminoff avatar pborreli avatar peterdavehello avatar radarhere avatar rdjs avatar schnerd avatar villevuor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vivus's Issues

Prevent path from animating

I've got an intricate SVG image with many paths, I only want one path to animate.

The path I want to animate is a stroke. The rest of the paths are filled shapes.

I find if I make the whole SVG strokes, the animation works, but if the animation is made up of fill paths and strokes, the animation doesn't work at all.

I would expect all the shape paths to stay static, and the stroke to animate, that's what I want.

Is there a way I can label a path to not animate? or tell all paths to not animate except for one?

Many thanks,

Possible to animate fill aswell?

At the moment (as far as I can tell) it is only possible to animate stroke. It could be pretty awesome if the "fill" attribute was animated aswell.

Anyways, awesome script!

Error when trying to animate an SVG

It might just be a problem on my side, but here is my code:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Test</title>
        <script src="js/vivus.min.js"></script>
        <script type="text/javascript" charset="utf-8">
            var monitor = new Vivus('svg2', {type: 'oneByOne', duration: 200, start: 'inViewport'});
        </script>
    </head>
    <body>
        <!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   width="281"
   height="221.0146"
   id="svg2">
  <defs
     id="defs4" />
  <metadata
     id="metadata7">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     transform="translate(-14.5,-811.86218)"
     id="layer1">
    <rect
       width="280"
       height="180"
       ry="10"
       x="15"
       y="10"
       transform="translate(0,802.36218)"
       id="rect2984"
       style="fill:none;stroke:#2e3436" />
    <rect
       width="260"
       height="160.00003"
       ry="4.9999976"
       x="25.000008"
       y="822.36218"
       id="rect2986"
       style="fill:none;stroke:#2e3436" />
    <path
       d="m 215,1032.3622 c -15.85343,-10.2878 -29.59568,-21.7286 -30.8125,-40.00002 l -29.1875,0 -29.1875,0 C 124.59568,1010.6336 110.85343,1022.0744 95,1032.3622 l 60,0 z"
       id="use3000"
       style="fill:none;stroke:#2e3436;stroke-linecap:round;stroke-linejoin:round" />
    <path
       d="m 40.562935,981.92511 0,-139.56293 c 0,-2.45814 1.978933,-4.43707 4.43707,-4.43707 l 220.562935,0 c 2.45813,0 4.43707,1.97893 4.43707,4.43707 l 0,139.56293"
       id="rect3775"
       style="fill:none;stroke:#2e3436;stroke-width:1.1258713;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0" />
    <path
       d="m 40,45 230,0"
       transform="translate(0,802.36218)"
       id="path3778"
       style="fill:none;stroke:#2e3436;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
    <path
       d="m 50,42.5 a 2.5,2.5 0 1 1 -5,0 2.5,2.5 0 1 1 5,0 z"
       transform="matrix(0.67873304,0,0,0.67873304,14.563348,813.71286)"
       id="path3783"
       style="fill:none;stroke:#2e3436;stroke-width:1.47333336;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
    <path
       d="m 50,42.5 a 2.5,2.5 0 1 1 -5,0 2.5,2.5 0 1 1 5,0 z"
       transform="matrix(0.67873304,0,0,0.67873304,19.993213,813.71286)"
       id="path3785"
       style="fill:none;stroke:#2e3436;stroke-width:1.47333336;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
    <path
       d="m 50,42.5 a 2.5,2.5 0 1 1 -5,0 2.5,2.5 0 1 1 5,0 z"
       transform="matrix(0.67873304,0,0,0.67873304,25.423077,813.71286)"
       id="path3787"
       style="fill:none;stroke:#2e3436;stroke-width:1.47333336;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
    <rect
       width="220"
       height="25"
       ry="5"
       x="45"
       y="50"
       transform="translate(0,802.36218)"
       id="rect3789"
       style="fill:none;stroke:#2e3436;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
    <path
       d="m 45,982.36218 0,-95 c 0,-2.77 2.23,-5 5,-5 l 35,0 c 2.77,0 5,2.23 5,5 l 0,95"
       id="rect3791"
       style="fill:none;stroke:#2e3436;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0" />
    <path
       d="m 95,982.36218 0,-95 c 0,-2.77 2.23,-5 5,-5 l 160,0 c 2.77,0 5,2.23 5,5 l 0,95"
       id="rect3793"
       style="fill:none;stroke:#2e3436;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0" />
  </g>
</svg>
    </body>
</html>

And I get this error in the console:

Error: Vivus [contructor]: "element" parameter is not related to an existing ID

Callback after finish on trigger for example play()

Is there anyway to callback after animation on click when I trigger for example animation with myVivus.play()?
And by the way what time is .play(1)? its not 1000ms can I set it somehow on specific time value in for example "mili seconds"?

Thank you in advance

Drawing path with stroke attribute set to "none"

Hello Maxwellito !

First thanks for your lib, it works well and that's nice !
I was playing around with some SVG when i found a path element in some random SVG used only to fill areas: the stroke attribute was set to "none".
This is breaking the animation when the oneByOne option is used because you have to wait for the invisible path to finish before going on.

I made a very simple modification to remove paths that have stroke set to none. Do you think it would be interesting to add this ? ( I can make a P.R. if you want)

Vivus.prototype.mapping = function () {
  var i, paths, path, pAttrs, pathObj, totalLength, lengthMeter, timePoint;
  timePoint = totalLength = lengthMeter = 0;
  paths = this.el.querySelectorAll('path');

 // START: Added part
  var cleanPaths = [];
  for (i = 0; i < paths.length; i++) {
    path = paths[i];
    if(path.getAttribute("stroke") === "none"){
      continue;
    }
    cleanPaths.push(path);
  }
  paths = cleanPaths;
// END: Added part

  for (i = 0; i < paths.length; i++) {
    path = paths[i];
    pathObj = {
      el: path,
      length: Math.ceil(path.getTotalLength())
    };
  ...
};

Invalid path attribute error

i am getting loads of those errors (chrome 40)

Error: Invalid value for attribute d="ML135.895,198.852L377.182,198.852L377.182,126.803L448.269,1.665"
vivus.min.js:7 r.pathMakervivus.min.js:7 r.scanvivus.min.js:7 rvivus.min.js:7 n.initvivus.min.js:7 (anonymous function)

for this kind of polylines:

any pointers much appreciated?

Should 'async' actually be 'sync'?

Kudos for the great work! Looking forward to using this in my next project.

Just a little nitpick here. I was confused by the usage of the term async to describe the second animation option. In my experience, async is a term used to describe things that happen at disparate times—not in a synchronized fashion. I think sync (synchronous or synchronized) may be what you're after to describe that effect?

screen shot 2015-02-26 at 1 20 34 pm

screen shot 2015-02-26 at 1 22 12 pm

NaN startAt, duration and progress

Hi, your library seems lovely, I was doing the same thing using Velocity but I decided to use your library instead.

So, I have two big SVGs, I was happy testing the first one, everything went smooth, but after testing the second one, it didn't work, as you mentioned in the Debugging section, I checked out the map property and what I found was the startAt, duration and progress properties were NaN.

It seems to be a Firefox-only issue as it works on Chromium.
(Firefox 35.0a1, Chromium 38)

Screenshot (console.table — Firefox):
vivus-bug

Jquery Function callbacks fails the SVG animation

Hey maxwellito,
This Script is great and working fine, I am quite happy with the results and the truth that animating an svg can be that easy. But I found a problem when ever I try callback a function using jquery that fails the animation but when I try the same thing with the JavaScript it works fine. First I thought that it may be a syntax error but I checked all the syntax, I found nothing wrong. But the JavaScript seems to work fine. I am not sure that is mine problem or did any one else faced it. any help i will appreciate,

Effect does not run

I am unable to get Vivus to apply the effect to any SVG I give it.

See for example http://jsfiddle.net/4Lvfqv83/

I tried removing encasing HTML and attributes from the <svg> tag, to no avail.
The console does not output anything.

Not working in Opera

Hi,

very nice plugin, thanks for sharing!

Not sure why, but Opera is throwing this error (also when visiting the demo site):
Uncaught exception: Error: Vivus [constructor]: "element" parameter must be a string or a SVGelement

Any ideas?

Thanks

Performance of external svg on browsers

I know that you said in your notes that the performance on older versions of Firefox does not perform to well but I have noticed that the svg does not animate at all on the latest version of Firefox (Mac and PC) and just displays a static SVG file. This happens when using an external SVG and not doing it inline. Using the SVG tags inline in the HTML document works absolutely fine.

Also it's causing IE11 browser to pretty much hang for a few minutes and then display a static SVG at the end as well (never been a big fan of IE but we have to support it).

It would be nice to work externally on the browsers as it would be good to avoid writing all the SVG code inline.

Change the direction of the animation

Hi! Thank you very much for the js, its great and works perfectly.
I only have a problem, i would like to change the direction of the animation of one of my paths and i dont know how. Its a word, and it should appear from left to right, not like now that appears right to left. Can you help me?
The path is the following:

<svg version="1.1" id="can-horizontal" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
                     viewBox="677.1 0 1628.9 350" enable-background="new 677.1 0 1628.9 350" onclick="can.reset().play();">
<path fill="none" stroke="#DD5A43" stroke-width="2" stroke-miterlimit="10" d="M2147.8,244.6c-113.3-45.7-286.2,117.6-318.8-8.1
                    c-47.9-184.3,201.1-65.4,9.8,7.3c-103.1,39.2-96.7-134.2-174.7-131.6c-20,0.7-90.6,14.9-108.1-10.3c-8-11.6-5.8-24.3-9.4-40.4
                    c-0.1-0.1-0.2-0.1-0.2,0c1,15.9,3.5,47.4-14.4,58c-19.6,11.6-31.6-1-32.2-10.4c-1.4-21.2,13.8-45.9,33.4-52c0.9-0.3,1.7,1,0.9,1.6
                    c-15.1,10.9-26.1,60.6-44.3,76c-8.8,7.3-24.1,8.4-33-9.6c-24.3-49.1-26.7-111.8-17.3-111.8c18.7,0,29,100.6-13.7,129
                    c-46.4,30.9-71.6-23.9-24-11.4c24.8,6.5,34.4,26.9,24.1,44.2c-5.6,9.3-20.8,14.1-35.1,10.3c-11.7-3.1-20-16.3-12.8-17.9
                    c7.2-1.6,8.2,29.9-3.4,35.4c-20.5,9.8-26.3-39.7-44.8-37.7c-9.1,1-10.6,12.3-10.9,19c-0.7,15,2.5,30.4,8.1,44.2
                    c0.1,9.6-27.2-73.1-46.8-108.6c-23.3-42.4-1.3-56.5,13.4-9.5c6.9,21.9,12.4,58.5,11.6,93.6c-1.9,88.4-296.1,35.3-452.2,59.1
                    c-152,23.1-1.5,131.1,7.3,8.1c1.8-25.6-14-59.3-51.2-100.8"/>
</svg>

And the script

    function easeOutBounce (x) {
        var base = -Math.cos(x * (0.5 * Math.PI)) + 1;
        var rate = Math.pow(base,1.5);
        var rateR = Math.pow(1 - x, 2);
        var progress = -Math.abs(Math.cos(rate * (2.5 * Math.PI) )) + 1;
        return (1- rateR) + (progress * rateR);
    }
        can = new Vivus('can-horizontal', {type: 'OneByOne', duration: 150});

Hope you can help me!
Thanks again! :)

Can't animate lines with x/y as percentage

<svg id="square" x="0px" y="0px" width="100%" height="100%">
    <line fill="#FFFFFF" stroke="#000000" stroke-width="20" x1="0" y1="0" x2="100%" y2="0"/>
    <line fill="#FFFFFF" stroke="#000000" stroke-width="20" x1="100%" y1="0" x2="100%" y2="100%"/>
    <line fill="#FFFFFF" stroke="#000000" stroke-width="20" x1="100%" y1="100%" x2="0" y2="100%"/>
    <line fill="#FFFFFF" stroke="#000000" stroke-width="20" x1="0" y1="100%" x2="0" y2="0"/>
</svg>

Returns the following error in the console:

[Error] Error: Problem parsing d="M0,0L100%,0"
    pathMaker (app.min.js, line 1)
    scan (app.min.js, line 1)
    t (app.min.js, line 1)
    e (app.min.js, line 1)
    (anonymous function) (app.min.js, line 1)
    j (jquery-1.11.1.min.js, line 2)
    fireWith (jquery-1.11.1.min.js, line 2)
    ready (jquery-1.11.1.min.js, line 2)
    J (jquery-1.11.1.min.js, line 2)
[Error] Error: Problem parsing d="M100%,0L100%,100%"
    pathMaker (app.min.js, line 1)
    scan (app.min.js, line 1)
    t (app.min.js, line 1)
    e (app.min.js, line 1)
    (anonymous function) (app.min.js, line 1)
    j (jquery-1.11.1.min.js, line 2)
    fireWith (jquery-1.11.1.min.js, line 2)
    ready (jquery-1.11.1.min.js, line 2)
    J (jquery-1.11.1.min.js, line 2)
[Error] Error: Problem parsing d="M100%,100%L0,100%"
    pathMaker (app.min.js, line 1)
    scan (app.min.js, line 1)
    t (app.min.js, line 1)
    e (app.min.js, line 1)
    (anonymous function) (app.min.js, line 1)
    j (jquery-1.11.1.min.js, line 2)
    fireWith (jquery-1.11.1.min.js, line 2)
    ready (jquery-1.11.1.min.js, line 2)
    J (jquery-1.11.1.min.js, line 2)
[Error] Error: Problem parsing d="M0,100%L0,0"
    pathMaker (app.min.js, line 1)
    scan (app.min.js, line 1)
    t (app.min.js, line 1)
    e (app.min.js, line 1)
    (anonymous function) (app.min.js, line 1)
    j (jquery-1.11.1.min.js, line 2)
    fireWith (jquery-1.11.1.min.js, line 2)
    ready (jquery-1.11.1.min.js, line 2)
    J (jquery-1.11.1.min.js, line 2)

Is this not possible with percentages?

Using vivus with img tag

The HTML:
<img id="graph" src="graph.svg">

and Javascript:
new Vivus('graph', {type: 'delayed', duration: 200});
or:

var g = document.getElementById('graph');
new Vivus(g, {type: 'delayed', duration: 200});

Results in:
Uncaught Error: Vivus [contructor]: "element" parameter must be a string or a SVGelement

Auto-recording SVG delays while drawing

Hello,

Do you know of any software that will record the stroke delays as they are drawn in real time? Instead of having to tweak the DOM to scenarize.

Thanks
Ulises

Animation type request: by path length

I imagine an option that delays the drawing of small path at the end of the animation. In this case, the details of the drawing are added in the end only. For example, in the case of a face, it can be nice to simulate a drawer’s process and trace eyes details in the end, after the main paths of the silhouette.
I can imagine that the oneByOne type simply respect the initial order of the paths in the SVG, but I think designers shouldn’t have to care about the animation while they design a shape.
Maybe this can be done simply by ordering paths drawing by length. What do you thin?

Need Commas in Path Elements?

I have some paths that look like this:

<path stroke:#000000;stroke-width:1px;stroke-linecap:butt; d="m 57.6 24.2 2.2 2 c 2.6 -2.8 6.2 -4.4 10 -4.4 3.8 0 7.5 1.6 10 4.4 l 2.2 -2 c -3.1 -3.5 -7.6 -5.4 -12.2 -5.4 -4.7 0 -9.1 2 -12.2 5.4 z"/>

Vivus doesn't seem to recognize these paths, as they aren't drawn. I saw in #40 that you mentioned the use of commas - are these necessary in Vivus SVGs?

Embed into object tag

Hey @jolic
I continue the topic here.
I wanted to implement your idea but after looking at your code, can you tell me why you need this:

var _checkElm = function(elm){
    if (elm.constructor === SVGSVGElement) {
        return true;
    }
    if ( typeof elm === 'object' && typeof elm.nodeName !== 'undefined' && elm.nodeName.toLowerCase() === 'svg') {
        return true;
    }
    return false;
};

Because when I look at the way you implement it, you still provide an SVG object to Vivus. I tried your fork with the unpatched version and it works fine.

Can you give me more details about it please?
Thanks :)

SVG font --> animated logo. How do I?

Given an svg file for a font, I'd like to make a vivus effect such that each letter of my logo (which is in this font) loads in parallel. How would I go about that? Things tried:
I used illustrator to make an SVG of the logo. Not sure this is the right approach (would rather just type out the letters)
Then, loading from a file using the second syntax listed. That caused this error, and the logo loaded all at once, no effect:

 Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLObjectElement':
 Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and
 ports must match.

The issue seems to be with chrome. So I loaded chrome without security settings. Now the logo loads all at once without effect, but no error either.

I tried putting all the svg from the illustrator file into my html. Didn't work either.

I feel like there's some easy way to do this I'm missing.

My svg start at the begining

Hello, I'm wondering why my svg start at the begining even i put

var myVivus = new Vivus('Layer_1');
var myVivus2 = new Vivus('Layer_2');
myVivus.reset().stop();
myVivus2.reset().stop();

and it works for chrome but doesn't work for other browsers, so animation fires at the begining after load, how can I stop drawing at the begining and only fire it up at ,y will ?

btw. thanks for great work :)

Strange behavior according to browser aspect ratio.

I discovered a strange behavior according to browser aspect ratio (width x height).
I am testing on MBP 15 inch (Chrome last version). On full screen mode all callbacks fires, console shows no errors, but nothing happens. SVG disappears as it should be, but drawing does not start. Doing absolutely nothing but decrease browser width (with the same height), drawing starts as it should. I completely remove all my media queries in css (for a rock solid tests), it does not help.

Entire path display before animation

Hi!

your script is great, thanks very much!

I only have one problem: the entire path is showing before animation start.
Do you have any idea how to fix this?

Easy Ease

I can't figure out a way to easy ease the animations as you would traditional with css, is it possible to implement at all?

Add a link

Hi,

Could you please help me to add a link to an animated SVG file? Is it possible to add url parameter in this code?

new Vivus('my-svg-id', {
type: 'delayed',
duration: 200,
animTimingFunction: Vivus.EASE
},);

Thanks

FF can not retrieve path length

I do get this error only in FF.

Vivus [mapping]: cannot retrieve a path element length

Chrome and Safari works fine.
Any idea on this? All path elements. Does FF render svgs differently?

support for "text" elements

Hi,

Great lib - but wondering why there isn't support for svg text elements, and if there is any plan to add support.

html:

    <svg id="t2">
        <text x="250" y="250" fill="none" stroke="#ffffff" style="stroke-width: 1px;">Test</text>
    </svg>

js:

    var v_text2 = new Vivus('t2', { type: 'delayed', duration: 200, start: 'autostart' });

This example makes me think it should be doable, but i'm very new to svg stuff so maybe I'm missing something:
http://codepen.io/yoksel/pen/XJbzrO

Thanks!

Peity SVG animations

Would Vivus work on http://benpickles.github.io/peity/? The charts generated look like:

<svg class="peity" height="16" width="32">
    <polygon fill="#c6d9fd" points="0 15.5 0 7.166666666666666 3.5555555555555554 10.5 7.111111111111111 0.5 10.666666666666666 5.5 14.222222222222221 7.166666666666666 17.77777777777778 0.5 21.333333333333332 3.833333333333334 24.888888888888886 10.5 28.444444444444443 7.166666666666666 32 12.166666666666668 32 15.5"></polygon>
    <polyline fill="transparent" points="0 7.166666666666666 3.5555555555555554 10.5 7.111111111111111 0.5 10.666666666666666 5.5 14.222222222222221 7.166666666666666 17.77777777777778 0.5 21.333333333333332 3.833333333333334 24.888888888888886 10.5 28.444444444444443 7.166666666666666 32 12.166666666666668" stroke="#4d89f9" stroke-width="1" stroke-linecap="square"></polyline>
</svg>

Converting fill to stroke

Hi, this isn't really an issue with vivus.js itself. I'm just looking for anyone who has advice on what I'm trying to do. If this is not the right place to post this, I apologise.

Currently new to svg and tried to animate an icon. (http://www.flaticon.com/free-icon/piece-of-cheese_69671) But it hit me that vivus works on svg with paths that are strokes, or shapes, with no fill. However, most outline icons I find are filled.

I'm wondering if anyone knows a quick way to convert these filled paths into strokes. Or, if you know of a good stroke svg icon resource online that works with vivus. I have tried googling but found no answer. If you can offer any advice I will be very grateful :) Would love very much to explore svgs more!

endless

is there no callback on reverse animation?
Put this as a callback
switch (tick) {
case 0:
tick=1;
hi.reset().play();
break;
case 1:
tick=0;
hi.play(-1);
break;
}
But the reverse animation does just come up once. how to make it infinite?

Publish as webjar

It would be nice to be able do download vivus as webjar.
See:

We could do the initial work for you and you could fork it and maintain it.
Or we can do all the work and mantain it. As you like 😄

Here is the tested pom.xml for the webjar. Just type mvn package.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>7</version>
    </parent>

    <packaging>jar</packaging>
    <groupId>org.webjars</groupId>
    <artifactId>vivus</artifactId>
    <version>0.1.2</version>
    <name>vivus</name>
    <description>WebJar for vivus</description>
    <url>http://webjars.org</url>

    <developers>
        <developer>
            <id>maxwellito</id>
            <name>maxwellito.com</name>
        </developer>
    </developers>

    <licenses>
        <license>
            <name>MIT</name>
            <url>https://github.com/maxwellito/vivus/blob/master/LICENSE</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/[REPONAME]</url>
        <connection>scm:git:https://github.com/[REPONAME].git</connection>
        <developerConnection>scm:git:https://github.com/[REPONAME].git</developerConnection>
        <tag>HEAD</tag>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <upstream.version>0.1.2</upstream.version>
        <upstream.url>https://raw.githubusercontent.com/maxwellito/vivus/v${upstream.version}/dist</upstream.url>
        <destDir>${project.build.outputDirectory}/META-INF/resources/webjars/${project.artifactId}/${upstream.version}</destDir>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>wagon-maven-plugin</artifactId>
                <version>1.0-beta-4</version>
                <executions>
                    <execution>
                        <id>download-js</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>download-single</goal>
                        </goals>
                        <configuration>
                            <url>${upstream.url}</url>
                            <fromFile>vivus.js</fromFile>
                            <toDir>${destDir}</toDir>
                        </configuration>
                    </execution>
                    <execution>
                        <id>download-min-js</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>download-single</goal>
                        </goals>
                        <configuration>
                            <url>${upstream.url}</url>
                            <fromFile>vivus.min.js</fromFile>
                            <toDir>${destDir}</toDir>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.1</version>
            </plugin>

            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.5</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>sonatype-nexus-staging</serverId>
                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Alternate inViewport behavior

Right now, it seems that start: inViewport does not cause the animation to start until the image has reached the top of the screen. Could an alternate option be made so that it starts as soon as the top of the image reaches the bottom of the screen?

Also, is there a workaround that I can use until this functionality is implemented?

Specify width/height of rendered element?

Hi,

I was wondering if it would be possible to force the output animation to a certain width. Something like this:

new Vivus('animation', {
  file: '/image.svg',
  type: 'async',
  width: '800px'
});

Apparently Vivus delegates this setting to whatever is set at <svg width="Xmm" height="Ymm">, but given that we're dealing with vector images, it seems like we could override those values in order to scale the size of the resulting animation for different screen sizes. Actually, being able to set width: '80%' (of the parent container width) would be awesome.

(Kudos for the great work, again :)

SVG sprite issue?

Hi,

I'm using an SVG sprite (using this method https://css-tricks.com/svg-sprites-use-better-icon-fonts/), which I'm embedding inline. I've included the JS in my header and added this code in my footer:

new Vivus('heading-also-like', {type: 'delayed', duration: 200, start: 'inViewport'});
new Vivus('heading-trending', {type: 'delayed', duration: 200, start: 'inViewport'});
new Vivus('heading-latest', {type: 'delayed', duration: 200, start: 'inViewport'});

Unfortunately, it's not working, and I'm getting the following error:

Error: Vivus [constructor]: "element" parameter is not valid (or miss the "file" attribute)

Am I doing something wrong or does Vivus not support SVG sprites? If not, could you add support?

Thanks!

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.