Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Update scroll + scale test

Julian Garnier0d4231a001af
diff --git a/tests/playground/sandbox/index.html b/tests/playground/sandbox/index.html
index 406f9b60..3a62ee88 100644
--- a/tests/playground/sandbox/index.html
+++ b/tests/playground/sandbox/index.html
@@ -6,67 +6,46 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="../assets/css/styles.css" rel="stylesheet">
<style>
- body {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- justify-content: center;
- align-items: center;
- height: 100vh;
- --test-color: #00FF00;
- --x: 5rem;
- --y: 20rem;
- }
+body {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ width: 100%;
+ height: 500px;
+}
- .container {
- display: flex;
- flex-wrap: wrap;
- justify-content: center;
- align-items: center;
- flex-direction: column;
- gap: 1rem;
- padding: 1rem;
- }
+main {
+ height: 400px;
+ width: 400px;
+ background-color: wheat;
+ overflow-y: auto;
+ scale: .8;
+}
- .square {
- width: 100px;
- height: 100px;
- background: currentColor;
- border-radius: 1rem;
- padding: 1rem;
- }
+.page {
+ width: 100%;
+ height: 1000px;
+ position: relative;
+}
+
+.rectangle {
+ width: 100px;
+ height: 100px;
+ background: purple;
+ position: absolute;
+ bottom: 100px;
+}
- .button {
- border-radius: 1rem;
- padding: 1rem;
- }
- .demo .css-variables.square:after {
- position: absolute;
- opacity: .5;
- top: 0;
- left: 0;
- content: "";
- display: block;
- width: 100%;
- height: 100%;
- background: currentColor;
- border-radius: inherit;
- transform: scale(var(--pseudo-el-after-scale));
- }
</style>
</head>
<body>
- <div class="demo">
- <div class="medium row">
- <div class="css-variables square"></div>
- </div>
- <div class="medium row">
- <div class="css-variables square"></div>
- </div>
- <div class="medium row">
- <div class="css-variables square"></div>
+ <main>
+ <div class="page">
+ <div class="rectangle" id="target">
+ </div>
</div>
- </div>
+ </main>
<script type="module" src="./index.js"></script>
</body>
</html>
diff --git a/tests/playground/sandbox/index.js b/tests/playground/sandbox/index.js
index 7f11eb24..f102423b 100644
--- a/tests/playground/sandbox/index.js
+++ b/tests/playground/sandbox/index.js
@@ -1,46 +1,14 @@
-import { waapi, animate, $, set, stagger, spring, random, utils } from '../../../dist/modules/index.js';
-
-// const targets = $('.green');
-
-// const [$red] = $('.red');
-
-// set(targets, { y: () => random(-200, 200), x: () => random(-200, 200) });
-
-// set(targets, { backgroundColor: '#FF0000' });
-
-// let reverse = false;
-
-// const animation = animate(targets, {
-// x: 'var(--x)',
-// y: 'var(--y)',
-// backgroundColor: 'var(--test-color, #FF00FF)',
-// borderRadius: '40%',
-// rotate: 90,
-// scale: 1.25,
-// delay: stagger(100),
-// loop: true,
-// alternate: true,
-// onComplete: () => {
-// console.log('completed');
-// }
-// });
-
-// document.body.addEventListener('click', () => {
-// animation.revert();
-// });
-
-// Set the CSS variables as properties on the animated elements
-utils.set('.square', {
- '--radius': '4px',
- '--x': '0rem',
- '--pseudo-el-after-scale': '1', // applied to the pseudo element "::after"
- borderRadius: 'var(--radius)',
- translateX: 'var(--x)',
+import { waapi, animate, onScroll, $, set, stagger, spring, random, utils } from '../../../dist/modules/index.js';
+
+const container = document.querySelector("main");
+animate(".rectangle", {
+ x: "70px",
+ ease: "inOutCirc",
+ delay: 1000,
+ loopDelay: 1000,
+ loop: true,
+ autoplay: onScroll({
+ container,
+ debug: true
+ })
});
-
-// Animate the values of the CSS variables
-animate('.square', {
- '--radius': '20px',
- '--x': '16.5rem',
- '--pseudo-el-after-scale': '1.55' // Animates the ":after" pseudo element of the element
-});
\ No newline at end of file