Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Add Helpers section to documentation #151

Julian Garnier547c26693d3b
diff --git a/documentation/assets/css/documentation.css b/documentation/assets/css/documentation.css
index 5fa36321..07521226 100644
--- a/documentation/assets/css/documentation.css
+++ b/documentation/assets/css/documentation.css
@@ -31,7 +31,7 @@ body {
.color-callbacks { color: #5A87FF; } /* Blue */
.color-svg { color: #8453E3; } /* Purple */
.color-easings { color: #C26EFF; } /* Lavender */
-.color-misc { color: #FB89FB; } /* Pink */
+.color-helpers { color: #FB89FB; } /* Pink */
.content {
@@ -252,13 +252,13 @@ pre {
code {
font-family: "Input Mono Reg", "Space Mono", monospace;
font-size: 14px;
- line-height: 20px;
+ line-height: 25px;
white-space: pre-wrap;
}
.code-pane-description {
font-size: 15px;
- line-height: 20px;
+ line-height: 25px;
color: rgba(255,255,255,.7);
}
@@ -558,18 +558,16 @@ article {
text-align: center;
}
+.bottom.log {
+ padding-top: 10px;
+ padding-bottom: 10px;
+}
+
.logs {
pointer-events: none;
- display: -webkit-box;
- display: -ms-flexbox;
display: flex;
- -webkit-box-orient: vertical;
- -webkit-box-direction: normal;
- -ms-flex-direction: column;
- flex-direction: column;
- -webkit-box-align: center;
- -ms-flex-align: center;
- align-items: center;
+ flex-direction: column;
+ align-items: center;
position: absolute;
width: 100%;
height: 100%;
diff --git a/documentation/assets/js/site.js b/documentation/assets/js/site.js
index b6219b82..6a98f8c6 100644
--- a/documentation/assets/js/site.js
+++ b/documentation/assets/js/site.js
@@ -6,31 +6,25 @@ var createBouncyButtons = (function() {
anime.remove([pathEl, spanEl]);
anime({
targets: pathEl,
- d: 'M10,10 C10,10 50,7 90,7 C130,7 170,10 170,10 C170,10 172,20 172,30 C172,40 170,50 170,50 C170,50 130,53 90,53 C50,53 10,50 10,50 C10,50 8,40 8,30 C8,20 10,10 10,10 Z',
- elasticity: 700,
- offset: 0
- });
+ d: 'M10,10 C10,10 50,7 90,7 C130,7 170,10 170,10 C170,10 172,20 172,30 C172,40 170,50 170,50 C170,50 130,53 90,53 C50,53 10,50 10,50 C10,50 8,40 8,30 C8,20 10,10 10,10 Z'
+ }), 0;
anime({
targets: spanEl,
scale: 1.15,
- duration: 800,
- offset: 0
- });
+ duration: 800
+ }), 0;
}
function down() {
anime.remove([pathEl, spanEl]);
anime({
targets: pathEl,
- d: 'M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z',
- elasticity: 700,
- offset: 0
- });
+ d: 'M10,10 C10,10 50,9.98999977 90,9.98999977 C130,9.98999977 170,10 170,10 C170,10 170.009995,20 170.009995,30 C170.009995,40 170,50 170,50 C170,50 130,50.0099983 90,50.0099983 C50,50.0099983 10,50 10,50 C10,50 9.98999977,40 9.98999977,30 C9.98999977,20 10,10 10,10 Z'
+ }), 0;
anime({
targets: spanEl,
scale: 1,
- duration: 800,
- offset: 0
- });
+ duration: 800
+ }), 0;
}
el.onmouseenter = hover;
el.onmousedown = down;
@@ -74,19 +68,17 @@ var logoAnimation = (function() {
{ value: 0, duration: 20, delay: 500, easing: 'easeInQuart' },
{ value: 1, duration: 200, delay: 1000, easing: 'easeOutQuart' },
{ value: 0, duration: 400, delay: 500, easing: 'easeInBack' }
- ],
- offset: 0
- })
+ ]
+ }, 0)
.add({
targets: '.dot-i',
- translateY: { value: [-200, 0], duration: 500, elasticity: 400 },
+ translateY: { value: [-200, 0], duration: 500 },
scale: [
{ value: [0, 1], duration: 100, easing: 'easeOutQuart' },
{ value: 0, duration: 400, delay: 1400, easing: 'easeInBack' }
],
- delay: 1200,
- offset: 0
- })
+ delay: 1200
+ }, 0)
.add({
targets: '.fill.in',
strokeDashoffset: {
@@ -105,9 +97,8 @@ var logoAnimation = (function() {
value: 0,
duration: 1,
delay: function(el, i, t) { return 1900 + ( i * 80 ); },
- },
- offset: 0
- })
+ }
+ }, 0)
.add({
targets: '.fill.out',
strokeDashoffset: [
@@ -118,9 +109,8 @@ var logoAnimation = (function() {
delay: function(el, i) { return (i * 80); },
easing: 'easeInQuart'
}
- ],
- offset: 0
- })
+ ]
+ }, 0)
.add({
targets: '.line.out',
strokeDashoffset: {
@@ -134,16 +124,14 @@ var logoAnimation = (function() {
delay: function(el, i, t) { return 2000 + ( i * 100 ); },
duration: 200,
easing: 'linear'
- },
- offset: 0
- })
+ }
+ }, 0)
.add({
targets: '.icon',
opacity: { value: 1, duration: 10, delay: 2800, easing: 'linear' },
translateY: { value: 60, duration: 800 },
- delay: 4200,
- offset: 0
- })
+ delay: 4200
+ }, 0)
.add({
targets: '.icon-line',
strokeDashoffset: [
@@ -161,16 +149,14 @@ var logoAnimation = (function() {
duration: 800,
delay: 3400,
easing: 'easeInQuad'
- },
- offset: 0
- })
+ }
+ }, 0)
.add({
targets: ['.icon-text path', '.icon-text polygon'],
translateY: [50, 0],
opacity: { value: [0, 1], duration: 100, easing: 'linear' },
- delay: function(el, i, t) { return 4200 + ( i * 20 ); },
- offset: 0
- })
+ delay: function(el, i, t) { return 4200 + ( i * 20 ); }
+ }, 0)
.add({
targets: ['.logo-animation', '.description', '.button', '.credits'],
translateY: [50, 0],
diff --git a/documentation/index.html b/documentation/index.html
index 535ea74f..e4909343 100644
--- a/documentation/index.html
+++ b/documentation/index.html
@@ -2492,9 +2492,12 @@ animation.update = function(anim) {
<h3 class="demo-title">Motion path</h3>
<div class="demo-description">
<p>
- Returns a Function that converts svg path data into animatable values:
+ Animate an element relative to the <code>x</code>, <code>y</code> and <code>angle</code> values of an SVG path element.
+ </p>
+ <pre><code>var myPath = anime.path('svg path');</code></pre>
+ <p>
+ The path function returns a new Function that returns the specified property:
</p>
-<pre><code>var myPath = anime.path('svg path');</code></pre>
<table>
<thead>
<td>Parameters</td>
@@ -2983,6 +2986,238 @@ anime({
</div>
+</article>
+<!-- -->
+
+<!-- HELPERS -->
+<article id="easings" class="color-helpers">
+ <header>
+ <h2 class="demos-title">Helpers</h2>
+ </header>
+
+<div id="running" class="demo">
+ <h3 class="demo-title">running</h3>
+ <div class="demo-description">
+ <p>
+ <code>anime.running()</code> returns an Array of all active <i>Anime</i> instances currently running.
+ </p>
+ </div>
+ <div class="demo-content running-demo">
+ <div class="line">
+ <div class="small square shadow"></div>
+ <div class="small square el"></div>
+ </div>
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ <div class="line">
+ <div class="small triangle shadow"></div>
+ <div class="small triangle el"></div>
+ </div>
+ <div class="line">
+ <pre class="bottom log running-log"></pre>
+ </div>
+ </div>
+ <script>var running = function() {
+/*DEMO*/
+var runninLogEl = document.querySelector('.running-log');
+
+anime({
+ targets: '.running-demo .square.el',
+ translateX: 250,
+ direction: 'alternate',
+ loop: true,
+ easing: 'linear'
+});
+
+anime({
+ targets: '.running-demo .circle.el',
+ translateX: 250,
+ direction: 'alternate',
+ loop: true,
+ easing: 'easeInOutCirc'
+});
+
+anime({
+ targets: '.running-demo .triangle.el',
+ translateX: 250,
+ direction: 'alternate',
+ easing: 'easeInOutQuad',
+ loop: true,
+ run: function() {
+ runninLogEl.innerHTML = 'there are currently ' + anime.running.length + ' instances running';
+ }
+});
+
+/*DEMO*/
+}
+ </script>
+
+</div>
+
+<div id="remove" class="demo">
+ <h3 class="demo-title">remove</h3>
+ <div class="demo-description">
+ <p>
+ <code>anime.remove(targets)</code> let you remove targets from a running animation or timeline.<br>
+ The <code>targets</code> parameters accepts the same values as <a class="color-targets" href="#targets">Targets</a> property.
+ </p>
+ <code>anime.remove('.items');</code>
+ </div>
+ <div class="demo-content remove-demo">
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ <div class="line player align-items">
+ <button class="remove-el-button">Remove second targert</button>
+ </div>
+ </div>
+ <script>var remove = function() {
+/*DEMO*/
+anime({
+ targets: '.remove-demo .el',
+ translateX: 250,
+ direction: 'alternate',
+ loop: true,
+ easing: 'easeInOutQuad'
+});
+
+document.querySelector('.remove-el-button').addEventListener('click', function() {
+ anime.remove('.remove-demo .line:nth-child(2) .el');
+});
+/*DEMO*/
+}
+ </script>
+
+</div>
+
+<div id="getValue" class="demo">
+ <h3 class="demo-title">getValue</h3>
+ <div class="demo-description">
+ <p>
+ <code>anime.getValue(el, propertyName, unit)</code> let you get the original value of an element.<br>
+ Since <i>Anime</i> uses <a href="https://developer.mozilla.org/fr/docs/Web/API/Window/getComputedStyle">getComputedStyle</a> to access original CSS, the values are almost always returned in <code>'px'</code>, the third (optional) argument converts the value in the desired unit.
+ </p>
+ <pre><code>anime.getValue(domNode, 'width', 'rem');</code></pre>
+ <p class="warning">
+ Only inlined transforms values can be accessed <code>style="transform: rotate(45deg)"</code>
+ </p>
+ </div>
+ <div class="demo-content get-value-demo">
+ <div class="line">
+ <div class="large circle shadow"></div>
+ <div class="large circle el"></div>
+ </div>
+ <pre class="bottom log get-value-demo-log"></pre>
+ </div>
+ <script>var getValue = function() {
+/*DEMO*/
+var logEl = document.querySelector('.get-value-demo-log');
+var el = document.querySelector('.get-value-demo .el');
+
+logEl.innerHTML = '".el" width is ' + anime.getValue(el, 'width', 'rem') + 'rem';
+/*DEMO*/
+}
+ </script>
+
+</div>
+
+<div id="random" class="demo">
+ <h3 class="demo-title">random</h3>
+ <div class="demo-description">
+ <p>
+ <code>anime.random(minValue, maxValue)</code> return a random integer within a specific range.
+ </p>
+ <pre><code>var randomValue = anime.random(-100, 100);</code></pre>
+ </div>
+ <div class="demo-content random-demo">
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ <div class="line">
+ <div class="small circle shadow"></div>
+ <div class="small circle el"></div>
+ </div>
+ </div>
+ <script>var random = function() {
+/*DEMO*/
+function randomValues() {
+ anime({
+ targets: '.random-demo .el',
+ translateX: function() {
+ return anime.random(0, 250);
+ },
+ easing: 'easeInOutQuad',
+ duration: 750,
+ complete: randomValues
+ });
+}
+
+randomValues();
+/*DEMO*/
+}
+ </script>
+
+</div>
+
+<div id="tick" class="demo">
+ <h3 class="demo-title">tick</h3>
+ <div class="demo-description">
+ <p>
+ <code>animation.tick(time)</code> let you use an external requestANimationFrame loop.<br>
+ </p>
+ <p class="warning">
+ Don't forget to set the <code>autoplay</code> parameter to <code>false</code> to prevent the <i>Anime</i> built-in RAF loop to start.
+ </p>
+ </div>
+ <div class="demo-content tick-demo">
+ <div class="line">
+ <div class="circle shadow"></div>
+ <div class="circle el"></div>
+ </div>
+ </div>
+ <script>
+var customRAF = null;
+var tick = function() {
+if (customRAF) cancelAnimationFrame(customRAF);
+/*DEMO*/
+
+var animation = anime({
+ targets: '.tick-demo .el',
+ translateX: 250,
+ direction: 'alternate',
+ loop: true,
+ easing: 'easeInOutQuad',
+ autoplay: false
+});
+
+function loop(t) {
+ animation.tick(t);
+ customRAF = requestAnimationFrame(loop);
+}
+
+requestAnimationFrame(loop);
+/*DEMO*/
+}
+ </script>
+
+</div>
+
</article>
<!-- -->