JavaScript animation engine
Set default loop value to 1
Julian Garnierafa6f47b0217
diff --git a/anime.js b/anime.jsindex 8b86b4c0..5b7d739b 100644--- a/anime.js+++ b/anime.js@@ -29,7 +29,7 @@begin: undefined,run: undefined,complete: undefined,- loop: 0,+ loop: 1,direction: 'normal',autoplay: true,offset: 0@@ -655,15 +655,15 @@let instance = createNewInstance(params);instance.reset = function() {- const loops = instance.loop;const direction = instance.direction;+ const loops = instance.loop;instance.currentTime = 0;instance.progress = 0;instance.paused = true;instance.began = false;instance.completed = false;instance.reversed = direction === 'reverse';- instance.remaining = loops ? loops : (direction === 'alternate') ? 2 : 1;+ instance.remaining = direction === 'alternate' && loops === 1 ? 2 : loops;}function toggleInstanceDirection() {diff --git a/documentation/examples/anime-svg.html b/documentation/examples/anime-svg.htmlindex 889301ab..c89cf5d4 100644--- a/documentation/examples/anime-svg.html+++ b/documentation/examples/anime-svg.html@@ -24,9 +24,9 @@position: absolute;top: 0;left: 0;- width: 8px;- height: 8px;- margin: -4px 0 0 -4px;+ width: 12px;+ height: 12px;+ margin: -6px 0 0 -6px;background: white;}</style>@@ -43,13 +43,16 @@(function() {function generateDots() {- var current = 100;- var d = 'M20 100 60 100 80 ';+ var currentX = 70;+ var d = 'M20 100 50 100 60 ';for (var i = 0; i < 13; i++) {- d+= anime.random(20, 180) + ' ' + current + ' ';- current = current + 20;+ var highY = anime.random(5, 100);+ d+= 100 - highY + ' ' + currentX + ' ';+ currentX += 10;+ d+= 100 + highY + ' ' + currentX + ' ';+ currentX += 10;}- d+= '100 380 100';+ d+= '100 350 100';return d;}@@ -58,17 +61,6 @@var pathAnim = function() {pathEl.setAttribute('d', generateDots());var path = anime.path(pathEl);- anime({- targets: pathEl,- easing: 'linear',- strokeDashoffset: [anime.setDashoffset, 0],- duration: 2000,- opacity: {- value: [1, 0],- duration: 100,- delay: 1800- }- });anime({targets: '.el',translateX: path('x'),@@ -76,10 +68,21 @@rotate: path('angle'),scale: [{ value: [4, 1], duration: 200 },- { value: [1, 0], duration: 200, delay: 1600 }+ { value: [1, 0], duration: 200, delay: 3000 }],easing: 'linear',- duration: 2000,+ duration: 3000+ });+ anime({+ targets: pathEl,+ easing: 'linear',+ strokeDashoffset: [anime.setDashoffset, 0],+ duration: 3000,+ opacity: {+ value: [1, 0],+ duration: 400,+ delay: 3000+ },complete: pathAnim});}diff --git a/documentation/examples/direction-testing.html b/documentation/examples/direction-testing.htmlnew file mode 100644index 00000000..b3a071bb--- /dev/null+++ b/documentation/examples/direction-testing.html@@ -0,0 +1,155 @@+<!DOCTYPE html>+<html>+<head>+ <title>Diretion Testing | anime.js</title>+ <meta charset="utf-8">+ <link rel="icon" type="image/png" href="../assets/img/favicon.png" />+ <link href="../assets/css/anime.css" rel="stylesheet">+ <script src="../../anime.js"></script>+ <style>+ body {+ display: flex;+ flex-wrap: wrap;+ align-items: center;+ justify-content: flex-start;+ height: auto;+ }+ article {+ padding: 2vw;+ position: relative;+ width: 33vw;+ height: 140px;+ background: currentColor;+ }+ h2 {+ color: #111116;+ }+ .el {+ margin-top: 2vw;+ width: 2vw;+ height: 2vw;+ background: #111116;+ }+ input {+ position: absolute;+ top: 2vw;+ left: 0;+ bottom: 0;+ width: 100%;+ text-align: center;+ background: none;+ border: none;+ }+ </style>+</head>+<body>+ <script>+ function createTest(title, numberOfTargets, params) {+ var testEl = document.createElement('article');+ var testZoneEl = document.createElement('div');+ var logEl = document.createElement('input');+ var h2El = document.createElement('h2');++ for (var i = 0; i < numberOfTargets; i++) {+ var el = document.createElement('div');+ el.classList.add('el');+ testZoneEl.appendChild(el);+ }++ h2El.innerHTML = title;+ testEl.appendChild(h2El);+ testEl.appendChild(logEl);+ testEl.appendChild(testZoneEl);+ document.body.appendChild(testEl);++ params.targets = testZoneEl.querySelectorAll('div');+ params.translateX = '26vw';+ params.begin = function() { testEl.classList.add('color-01') };+ params.update = function(a) { logEl.value = a.progress + '%' };+ params.complete = function() { testEl.classList.add('color-04') };+ anime(params);+ }++ createTest('Normal', 1, {});++ createTest('Reverse', 1, {+ direction: 'reverse'+ });++ createTest('Alternate', 1, {+ direction: 'alternate'+ });++ createTest('Normal 1 times', 1, {+ loop: 1+ });++ createTest('Reverse 1 times', 1, {+ direction: 'reverse',+ loop: 1+ });++ createTest('Alternate 1 times', 1, {+ direction: 'alternate',+ loop: 1+ });++ createTest('Normal 2 times', 1, {+ loop: 2+ });++ createTest('Reverse 2 times', 1, {+ direction: 'reverse',+ loop: 2+ });++ createTest('Alternate 2 times', 1, {+ direction: 'alternate',+ loop: 2+ });++ createTest('Normal 3 times', 1, {+ loop: 3+ });++ createTest('Reverse 3 times', 1, {+ direction: 'reverse',+ loop: 3+ });++ createTest('Alternate 3 times', 1, {+ direction: 'alternate',+ loop: 3+ });++ createTest('Normal loop true', 1, {+ loop: true+ });++ createTest('Reverse loop true', 1, {+ direction: 'reverse',+ loop: true+ });++ createTest('Alternate loop true', 1, {+ direction: 'alternate',+ loop: true+ });++ createTest('Normal infinite times', 1, {+ loop: Infinity+ });++ createTest('Reverse infinite times', 1, {+ direction: 'reverse',+ loop: Infinity+ });++ createTest('Alternate infinite times', 1, {+ direction: 'alternate',+ loop: Infinity+ });++ </script>+</body>+</html>