| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Controls (chain / seek / scroll) - Animal.js</title>
- <link rel="stylesheet" href="../demo.css">
- <style>
- .demo-visual {
- gap: 18px;
- }
- .row {
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- gap: 14px;
- }
- .box {
- width: 48px;
- height: 48px;
- border-radius: 10px;
- background: var(--highlight-color);
- transform: translateX(0px);
- }
- .bar-wrap {
- width: 100%;
- background: rgba(255,255,255,0.05);
- border: 1px solid rgba(255,255,255,0.08);
- border-radius: 999px;
- overflow: hidden;
- height: 10px;
- }
- .bar {
- height: 100%;
- width: 0%;
- background: var(--orange);
- }
- .hint {
- font-size: 12px;
- color: #888;
- }
- .spacer {
- height: 80vh; /* enough to scroll inside the iframe */
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="page-top">
- <div class="crumb">ANIMATION > EXAMPLES</div>
- <div class="since">CONTROLS</div>
- </div>
- <h1>Controls</h1>
- <p class="description">
- <code class="inline">animate()</code> returns a <strong>thenable controls object</strong>.
- You can <code class="inline">play/pause</code>, <code class="inline">seek()</code> (0..1),
- and wire it to <code class="inline">scroll()</code>.
- </p>
- <div class="box-container">
- <div class="box-header">
- <div class="box-title">Controls example</div>
- <div class="tabs">
- <div class="tab active" onclick="switchTab('js')">JavaScript</div>
- <div class="tab" onclick="switchTab('html')">HTML</div>
- </div>
- </div>
- <pre id="js-code" class="code-view active">const $ = animal;
- const ctl = $('.ex-box').animate({
- x: 220,
- rotate: 180,
- opacity: 0.6,
- duration: 800,
- autoplay: false
- });
- // chainable controls
- ctl.seek(0.25).play();
- // still awaitable / thenable
- ctl.then(() => console.log('done'));
- // scroll-linked (works with WAAPI + JS fallback)
- const progress = $('.ex-bar').animate({
- width: ['0%', '100%'],
- autoplay: false,
- duration: 1000
- });
- $.scroll(progress);</pre>
- <pre id="html-code" class="html-view"><div class="ex-box"></div>
- <div class="bar-wrap">
- <div class="ex-bar"></div>
- </div></pre>
- <div class="demo-visual">
- <div class="row">
- <div class="box ex-box" aria-label="demo box"></div>
- <div class="hint">Click REPLAY, then scroll inside this panel.</div>
- </div>
- <div class="bar-wrap">
- <div class="bar ex-bar" aria-label="progress bar"></div>
- </div>
- <div class="spacer"></div>
- <div class="hint">Scroll target area (spacer)</div>
- </div>
- <div class="action-bar">
- <button class="play-btn" onclick="runDemo()">REPLAY</button>
- </div>
- </div>
- </div>
- <script src="../../animal.js"></script>
- <script>
- function switchTab(tab) {
- document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
- document.querySelectorAll('.code-view, .html-view').forEach(v => v.classList.remove('active'));
- if (tab === 'js') {
- document.querySelector('.tabs .tab:nth-child(1)').classList.add('active');
- document.getElementById('js-code').classList.add('active');
- } else {
- document.querySelector('.tabs .tab:nth-child(2)').classList.add('active');
- document.getElementById('html-code').classList.add('active');
- }
- }
- let cleanup = null;
- function runDemo() {
- const $ = animal;
- // reset
- const box = document.querySelector('.ex-box');
- const bar = document.querySelector('.ex-bar');
- box.style.transform = 'none';
- box.style.opacity = '1';
- bar.style.width = '0%';
- // Remove previous scroll listener if any
- if (cleanup) cleanup();
- cleanup = null;
- const ctl = $('.ex-box').animate({
- x: 220,
- rotate: 180,
- opacity: 0.6,
- duration: 800,
- autoplay: false
- });
- ctl.seek(0.25).play();
- const progress = $('.ex-bar').animate({
- width: ['0%', '100%'],
- autoplay: false,
- duration: 1000
- });
- cleanup = $.scroll(progress);
- }
- setTimeout(runDemo, 300);
- </script>
- </body>
- </html>
|