Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Better check unit caching

Julian Garnier0bc42b0bd37e
diff --git a/anime.js b/anime.js
index e827ab06..f3edc84d 100644
--- a/anime.js
+++ b/anime.js
@@ -446,7 +446,7 @@
const valueUnit = getUnit(value);
if (arrayContains([unit, 'deg', 'rad', 'turn'], valueUnit)) return value;
const cached = cache.CSS[value + unit];
- if(cached) return cached;
+ if (!is.und(cached)) return cached;
const baseline = 100;
const tempEl = document.createElement(el.tagName);
const parentEl = el.parentNode || document.body;
diff --git a/documentation/examples/anime-DOM-stress-test-02.html b/documentation/examples/anime-DOM-stress-test.html
similarity index 60%
rename from documentation/examples/anime-DOM-stress-test-02.html
rename to documentation/examples/anime-DOM-stress-test.html
index 0090865f..cbb7c53e 100644
--- a/documentation/examples/anime-DOM-stress-test-02.html
+++ b/documentation/examples/anime-DOM-stress-test.html
@@ -17,7 +17,7 @@
<link rel="icon" type="image/png" href="../assets/img/icons/favicon.png" >
<link href="../assets/css/anime.css" rel="stylesheet">
<script src="../../anime.js"></script>
- <!-- <script src="../assets/js/anime.2.0.2.js"></script> -->
+ <!-- <script src="../assets/js/anime/anime.2.0.2.js"></script> -->
<!-- <script src="../assets/js/anime.1.0.js"></script> -->
<style>
@@ -32,11 +32,7 @@
width: 1em;
height: 1em;
margin: -.5em 0 0 -.5em;
- /*border: .05em solid currentColor;*/
- /*background-color: currentColor;*/
font-size: 40px;
- /*border-radius: 50%;*/
- transform: scale(0);
}
</style>
@@ -44,47 +40,38 @@
<body></body>
<script>
+ anime.speed = -1;
+
const wrapperEl = document.body;
- const numberOfEls = 280;
- const duration = 3000;
- const delay = duration / numberOfEls;
+ const numberOfEls = 1000;
const radius = window.innerWidth < window.innerHeight ? window.innerWidth : window.innerHeight;
- const distance = radius / 4 <= 150 ? 150 : radius / 3;
-
- let tl = anime.timeline({
- duration: delay,
- complete: function() { tl.restart(); }
- });
+ const distance = (radius / 4 <= 150 ? 150 : radius / 2.5) / 16;
function createEl(i) {
let el = document.createElement('div');
const hue = Math.round(360 / numberOfEls * i);
const angle = i;
el.classList.add('el');
- el.style.backgroundColor = 'hsl(' + hue + ', 40%, 60%)';
- tl.add({
- begin: function() {
- var randomDistance = anime.random(distance - 50, distance + 50);
- anime({
- targets: el,
- // backgroundColor: ['#fff', '#000'],
- translateX: [0, Math.sin(angle) * randomDistance],
- translateY: [0,Math.cos(angle) * randomDistance],
- scale: [
- {value: [0, anime.random(5, 10) * .1], easing: 'easeOutBack'},
- {value: 0, easing: 'easeInBack'},
- ],
- easing: 'easeInOutSine',
- direction: 'reverse',
- duration: duration
- });
- }
- });
+ el.style.border = '5px solid hsl(' + hue + ', 50%, 50%)';
wrapperEl.appendChild(el);
+ anime({
+ targets: el,
+ translateX: Math.sin(angle) * distance + 'rem',
+ translateY: Math.cos(angle) * distance + 'rem',
+ scale: [
+ {value: [0, 1]},
+ {value: 0}
+ ],
+ borderRadius: '50%',
+ easing: 'easeInOutSine',
+ loop: true,
+ duration: 1000,
+ delay: i * (8000 / numberOfEls)
+ });
};
for (let i = 0; i < numberOfEls; i++) createEl(i);
</script>
- <script src="../assets/js/stats.js"></script>
+ <script src="../assets/js/vendors/stats.min.js"></script>
</html>