| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>CSS Variables - Animal.js</title>
- <link rel="stylesheet" href="../demo.css">
- <style>
- :root {
- --box-width: 50px;
- }
- .box {
- width: var(--box-width);
- height: 50px;
- background-color: var(--highlight-color);
- border-radius: 4px;
- }
- .demo-visual { padding: 40px; display: flex; align-items: center; justify-content: center; }
- </style>
- </head>
- <body>
- <div class="container">
- <div style="font-size: 10px; font-weight: bold; letter-spacing: 1px; color: #ff4b4b; margin-bottom: 20px;">ANIMATION > ANIMATABLE PROPERTIES</div>
- <h1>CSS Variables</h1>
- <p class="description">Animate CSS variables directly.</p>
- <div class="box-container">
- <div class="box-header">
- <div class="box-title">CSS Var example</div>
- <div class="tabs"><div class="tab active">JavaScript</div></div>
- </div>
- <div id="js-code" class="code-view active">
- <span class="fun">animate</span><span class="punc">(</span><span class="str">'.box'</span><span class="punc">,</span> <span class="punc">{</span>
- <span class="str">'--box-width'</span><span class="punc">:</span> <span class="str">'200px'</span>
- <span class="punc">}</span><span class="punc">)</span><span class="punc">;</span>
- </div>
- <div class="demo-visual">
- <div class="box"></div>
- </div>
- <div class="action-bar"><button class="play-btn" onclick="runDemo()">REPLAY</button></div>
- </div>
- </div>
- <script src="../../animal.js"></script>
- <script>
- function runDemo() {
- // Note: Animal.js might handle CSS vars via standard style property setting.
- // WAAPI supports CSS variables in some browsers if registered,
- // but standard JS fallback usually handles it if implemented.
- // Let's see if simple style setting works or if we need a custom updater.
-
- // NOTE: animal.js 'animate' logic mainly targets keys in ALIASES or transforms.
- // Custom keys like '--box-width' might fall into 'jsProps'.
- // The JS loop: el.style[k] = val.
- // For CSS vars, one must use el.style.setProperty(k, val).
- // animal.js: "else if (k in el.style) { el.style[k] = val; }"
- // CSS vars are NOT "in el.style" directly as properties usually (they are via setProperty).
- // So animal.js might FAIL to animate CSS vars without modification.
-
- // Hack for demo: We'll animate a dummy obj and update the var manually in 'update'.
-
- const box = document.querySelector('.box');
- box.style.setProperty('--box-width', '50px');
-
- const proxy = { width: 50 };
- animal.animate(proxy, {
- width: 200,
- duration: 1000,
- update: () => {
- box.style.setProperty('--box-width', proxy.width + 'px');
- }
- });
- }
- setTimeout(runDemo, 500);
- </script>
- </body>
- </html>
|