| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Layer 自定义动画(Lottie)- Animal.js</title>
- <link rel="stylesheet" href="../demo.css">
- <link rel="stylesheet" href="../../xjs.css">
- <style>
- /* Keep Layer above the doc UI */
- .layer-overlay { z-index: 99999; }
- </style>
- <style>
- .controls {
- display: flex;
- flex-wrap: wrap;
- gap: 10px 12px;
- align-items: center;
- font-size: 13px;
- color: #b7b7b7;
- }
- .controls label {
- display: inline-flex;
- gap: 8px;
- align-items: center;
- cursor: pointer;
- user-select: none;
- }
- .controls input { accent-color: var(--highlight-color); }
- .row {
- display: flex;
- flex-wrap: wrap;
- gap: 10px;
- align-items: center;
- }
- .btn {
- appearance: none;
- border: 1px solid rgba(255,255,255,0.12);
- background: rgba(255,255,255,0.04);
- color: #fff;
- border-radius: 999px;
- padding: 10px 14px;
- font-weight: 650;
- cursor: pointer;
- transition: border-color 0.15s ease, background 0.15s ease;
- }
- .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
- .btn.disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
- .demo-visual { padding: 22px 24px; }
- .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="page-top">
- <div class="crumb">UI › LAYER</div>
- <div class="since">CUSTOM ANIMATION</div>
- </div>
- <h1>自定义动画(Lottie)</h1>
- <p class="description">
- 使用 <code class="inline">icon: "svg:<name>"</code> 触发 Lottie 图标渲染(基于 <code class="inline">svg/svg.js</code>)。
- 下面是当前内置的动画示例,后续可以继续往列表里加。
- </p>
- <div class="box-container">
- <div class="demo-visual">
- <div class="controls" style="margin-bottom: 14px;">
- <label><input id="optIcon" type="checkbox" checked> iconAnimation</label>
- <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
- <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
- </div>
- <div class="row">
- <button class="btn" type="button" onclick="openDemo('loadding')">Loading</button>
- <button class="btn" type="button" onclick="openDemo('banner')">Banner</button>
- <button class="btn" type="button" onclick="openDemo('BallSorting')">BallSorting</button>
- <button class="btn" type="button" onclick="openDemo('BallSorting', false)">Scale Pop</button>
- <button class="btn disabled" type="button" disabled>更多动画待加入...</button>
- </div>
- <div class="hint">
- Tip: 关闭 <code class="inline">popupAnimation</code> 可查看当前位置的缩放回弹效果。
- </div>
- </div>
- <div class="box-header">
- <div class="box-title">Controls</div>
- <div class="tabs">
- <div class="tab active" onclick="switchTab('js')">JavaScript</div>
- <div class="tab" onclick="switchTab('html')">HTML</div>
- <div class="tab" onclick="switchTab('css')">CSS</div>
- </div>
- </div>
- <pre id="js-code" class="code-view active">function openDemo(name, popupOverride) {
- if (typeof window.$ !== 'function') return;
- const iconAnimation = !!document.getElementById('optIcon')?.checked;
- const popupAnimation = (typeof popupOverride === 'boolean')
- ? popupOverride
- : !!document.getElementById('optPopup')?.checked;
- const closeOnEsc = !!document.getElementById('optEsc')?.checked;
- const iconBox = name === 'loadding' ? '11em' : null;
- const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
- Layer.run({
- title: titleCap,
- text: 'Lottie animation icon',
- icon: 'svg:' + name,
- iconAnimation,
- popupAnimation,
- closeOnEsc,
- iwidth: iconBox,
- iheight: iconBox
- });
- }</pre>
- <pre id="html-code" class="html-view"><div class="demo-visual">
- <div class="controls" style="margin-bottom: 14px;">
- <label><input id="optIcon" type="checkbox" checked> iconAnimation</label>
- <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
- <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
- </div>
- <div class="row">
- <button class="btn" type="button" onclick="openDemo('loadding')">Loading</button>
- <button class="btn" type="button" onclick="openDemo('banner')">Banner</button>
- <button class="btn" type="button" onclick="openDemo('BallSorting')">BallSorting</button>
- <button class="btn" type="button" onclick="openDemo('BallSorting', false)">Scale Pop</button>
- <button class="btn disabled" type="button" disabled>更多动画待加入...</button>
- </div>
- <div class="hint">
- Tip: 关闭 <code class="inline">popupAnimation</code> 可查看当前位置的缩放回弹效果。
- </div>
- </div></pre>
- <pre id="css-code" class="css-view">/* Keep Layer above the doc UI */
- .layer-overlay { z-index: 99999; }
- .controls {
- display: flex;
- flex-wrap: wrap;
- gap: 10px 12px;
- align-items: center;
- font-size: 13px;
- color: #b7b7b7;
- }
- .controls label {
- display: inline-flex;
- gap: 8px;
- align-items: center;
- cursor: pointer;
- user-select: none;
- }
- .controls input { accent-color: var(--highlight-color); }
- .row {
- display: flex;
- flex-wrap: wrap;
- gap: 10px;
- align-items: center;
- }
- .btn {
- appearance: none;
- border: 1px solid rgba(255,255,255,0.12);
- background: rgba(255,255,255,0.04);
- color: #fff;
- border-radius: 999px;
- padding: 10px 14px;
- font-weight: 650;
- cursor: pointer;
- transition: border-color 0.15s ease, background 0.15s ease;
- }
- .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
- .btn.disabled {
- opacity: 0.5;
- cursor: not-allowed;
- }
- .demo-visual { padding: 22px 24px; }
- .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }</pre>
- <div class="feature-desc">
- <strong>功能说明:</strong>本页验证 Layer 在 <code class="inline">icon</code> 传入 <code class="inline">svg:</code> 前缀时,
- 会自动加载 Lottie 库并渲染对应 JSON 动画。
- </div>
- </div>
- <div class="doc-nav" aria-label="Previous and next navigation">
- <a href="#" id="prevLink" onclick="goPrev(); return false;">
- <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
- <span aria-hidden="true">←</span>
- </a>
- <div class="nav-center" id="navCenter">Layer</div>
- <a href="#" id="nextLink" onclick="goNext(); return false;">
- <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
- <span aria-hidden="true">→</span>
- </a>
- </div>
- </div>
- <script src="../highlight_css.js"></script>
- <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
- <script>
- (function () {
- var b = Date.now();
- document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
- document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
- document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
- })();
- </script>
- <script>
- const CURRENT = 'layer/test_custom_animation.html';
- function switchTab(tab) {
- document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
- document.querySelectorAll('.code-view, .html-view, .css-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 if (tab === 'html') {
- document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
- document.getElementById('html-code')?.classList.add('active');
- } else {
- document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
- document.getElementById('css-code')?.classList.add('active');
- }
- }
- function openDemo(name, popupOverride) {
- if (typeof window.$ !== 'function') return;
- const iconAnimation = !!document.getElementById('optIcon')?.checked;
- const popupAnimation = (typeof popupOverride === 'boolean')
- ? popupOverride
- : !!document.getElementById('optPopup')?.checked;
- const closeOnEsc = !!document.getElementById('optEsc')?.checked;
- const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
- const iconBox = name === 'loadding' ? '11em' : null;
- // Keep the displayed code consistent with what is executed.
- const code = `Layer.run({
- title: '${titleCap}',
- text: 'Lottie animation icon',
- icon: 'svg:${name}',
- iconAnimation: ${iconAnimation},
- popupAnimation: ${popupAnimation},
- closeOnEsc: ${closeOnEsc},
- iwidth: ${iconBox ? `'${iconBox}'` : 'null'},
- iheight: ${iconBox ? `'${iconBox}'` : 'null'}
- });`;
- const jsPre = document.getElementById('js-code');
- if (jsPre) {
- jsPre.textContent = code;
- // Re-run syntax highlight after content change.
- try { jsPre.dataset.highlighted = '0'; } catch {}
- try { if (window.__highlightCssViews) window.__highlightCssViews(); } catch {}
- }
- Layer.run({
- title: titleCap,
- text: 'Lottie animation icon',
- icon: 'svg:' + name,
- iconAnimation,
- popupAnimation,
- closeOnEsc,
- iwidth: iconBox,
- iheight: iconBox
- });
- }
- function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
- function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
- function syncNavLabels() {
- const api = window.parent?.docGetPrevNext;
- if (typeof api !== 'function') return;
- const { prev, next, current } = api(CURRENT) || {};
- const prevLink = document.getElementById('prevLink');
- const nextLink = document.getElementById('nextLink');
- if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
- else { prevLink.style.visibility = 'hidden'; }
- if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
- else { nextLink.style.visibility = 'hidden'; }
- document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
- }
- try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
- syncNavLabels();
- </script>
- </body>
- </html>
|