test_custom_animation.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Layer 自定义动画(Lottie)- Animal.js</title>
  7. <link rel="stylesheet" href="../demo.css">
  8. <link rel="stylesheet" href="../../xjs.css">
  9. <style>
  10. /* Keep Layer above the doc UI */
  11. .layer-overlay { z-index: 99999; }
  12. </style>
  13. <style>
  14. .controls {
  15. display: flex;
  16. flex-wrap: wrap;
  17. gap: 10px 12px;
  18. align-items: center;
  19. font-size: 13px;
  20. color: #b7b7b7;
  21. }
  22. .controls label {
  23. display: inline-flex;
  24. gap: 8px;
  25. align-items: center;
  26. cursor: pointer;
  27. user-select: none;
  28. }
  29. .controls input { accent-color: var(--highlight-color); }
  30. .row {
  31. display: flex;
  32. flex-wrap: wrap;
  33. gap: 10px;
  34. align-items: center;
  35. }
  36. .btn {
  37. appearance: none;
  38. border: 1px solid rgba(255,255,255,0.12);
  39. background: rgba(255,255,255,0.04);
  40. color: #fff;
  41. border-radius: 999px;
  42. padding: 10px 14px;
  43. font-weight: 650;
  44. cursor: pointer;
  45. transition: border-color 0.15s ease, background 0.15s ease;
  46. }
  47. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  48. .btn.disabled {
  49. opacity: 0.5;
  50. cursor: not-allowed;
  51. }
  52. .demo-visual { padding: 22px 24px; }
  53. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  54. </style>
  55. </head>
  56. <body>
  57. <div class="container">
  58. <div class="page-top">
  59. <div class="crumb">UI › LAYER</div>
  60. <div class="since">CUSTOM ANIMATION</div>
  61. </div>
  62. <h1>自定义动画(Lottie)</h1>
  63. <p class="description">
  64. 使用 <code class="inline">icon: "svg:&lt;name&gt;"</code> 触发 Lottie 图标渲染(基于 <code class="inline">svg/svg.js</code>)。
  65. 下面是当前内置的动画示例,后续可以继续往列表里加。
  66. </p>
  67. <div class="box-container">
  68. <div class="demo-visual">
  69. <div class="controls" style="margin-bottom: 14px;">
  70. <label><input id="optIcon" type="checkbox" checked> iconAnimation</label>
  71. <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
  72. <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
  73. </div>
  74. <div class="row">
  75. <button class="btn" type="button" onclick="openDemo('loadding')">Loading</button>
  76. <button class="btn" type="button" onclick="openDemo('banner')">Banner</button>
  77. <button class="btn" type="button" onclick="openDemo('BallSorting')">BallSorting</button>
  78. <button class="btn disabled" type="button" disabled>更多动画待加入...</button>
  79. </div>
  80. <div class="hint">
  81. Tip: 将 Lottie JSON 放在 <code class="inline">/svg</code> 目录,按钮参数填 <code class="inline">svg:&lt;json文件名&gt;</code>。
  82. </div>
  83. </div>
  84. <div class="box-header">
  85. <div class="box-title">Controls</div>
  86. <div class="tabs">
  87. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  88. <div class="tab" onclick="switchTab('html')">HTML</div>
  89. <div class="tab" onclick="switchTab('css')">CSS</div>
  90. </div>
  91. </div>
  92. <pre id="js-code" class="code-view active">function openDemo(name) {
  93. if (typeof window.$ !== 'function') return;
  94. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  95. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  96. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  97. const iconBox = name === 'loadding' ? '11em' : null;
  98. const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
  99. Layer.run({
  100. title: titleCap,
  101. text: 'Lottie animation icon',
  102. icon: 'svg:' + name,
  103. iconAnimation,
  104. popupAnimation,
  105. closeOnEsc,
  106. iwidth: iconBox,
  107. iheight: iconBox
  108. });
  109. }</pre>
  110. <pre id="html-code" class="html-view">&lt;div class="demo-visual"&gt;
  111. &lt;div class="controls" style="margin-bottom: 14px;"&gt;
  112. &lt;label&gt;&lt;input id="optIcon" type="checkbox" checked&gt; iconAnimation&lt;/label&gt;
  113. &lt;label&gt;&lt;input id="optPopup" type="checkbox" checked&gt; popupAnimation&lt;/label&gt;
  114. &lt;label&gt;&lt;input id="optEsc" type="checkbox" checked&gt; closeOnEsc&lt;/label&gt;
  115. &lt;/div&gt;
  116. &lt;div class="row"&gt;
  117. &lt;button class="btn" type="button" onclick="openDemo('loadding')"&gt;Loading&lt;/button&gt;
  118. &lt;button class="btn" type="button" onclick="openDemo('banner')"&gt;Banner&lt;/button&gt;
  119. &lt;button class="btn" type="button" onclick="openDemo('BallSorting')"&gt;BallSorting&lt;/button&gt;
  120. &lt;button class="btn disabled" type="button" disabled&gt;更多动画待加入...&lt;/button&gt;
  121. &lt;/div&gt;
  122. &lt;div class="hint"&gt;
  123. Tip: 将 Lottie JSON 放在 &lt;code class="inline"&gt;/svg&lt;/code&gt; 目录,按钮参数填 &lt;code class="inline"&gt;svg:&amp;lt;json文件名&amp;gt;&lt;/code&gt;。
  124. &lt;/div&gt;
  125. &lt;/div&gt;</pre>
  126. <pre id="css-code" class="css-view">/* Keep Layer above the doc UI */
  127. .layer-overlay { z-index: 99999; }
  128. .controls {
  129. display: flex;
  130. flex-wrap: wrap;
  131. gap: 10px 12px;
  132. align-items: center;
  133. font-size: 13px;
  134. color: #b7b7b7;
  135. }
  136. .controls label {
  137. display: inline-flex;
  138. gap: 8px;
  139. align-items: center;
  140. cursor: pointer;
  141. user-select: none;
  142. }
  143. .controls input { accent-color: var(--highlight-color); }
  144. .row {
  145. display: flex;
  146. flex-wrap: wrap;
  147. gap: 10px;
  148. align-items: center;
  149. }
  150. .btn {
  151. appearance: none;
  152. border: 1px solid rgba(255,255,255,0.12);
  153. background: rgba(255,255,255,0.04);
  154. color: #fff;
  155. border-radius: 999px;
  156. padding: 10px 14px;
  157. font-weight: 650;
  158. cursor: pointer;
  159. transition: border-color 0.15s ease, background 0.15s ease;
  160. }
  161. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  162. .btn.disabled {
  163. opacity: 0.5;
  164. cursor: not-allowed;
  165. }
  166. .demo-visual { padding: 22px 24px; }
  167. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }</pre>
  168. <div class="feature-desc">
  169. <strong>功能说明:</strong>本页验证 Layer 在 <code class="inline">icon</code> 传入 <code class="inline">svg:</code> 前缀时,
  170. 会自动加载 Lottie 库并渲染对应 JSON 动画。
  171. </div>
  172. </div>
  173. <div class="doc-nav" aria-label="Previous and next navigation">
  174. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  175. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  176. <span aria-hidden="true">←</span>
  177. </a>
  178. <div class="nav-center" id="navCenter">Layer</div>
  179. <a href="#" id="nextLink" onclick="goNext(); return false;">
  180. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  181. <span aria-hidden="true">→</span>
  182. </a>
  183. </div>
  184. </div>
  185. <script src="../highlight_css.js"></script>
  186. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  187. <script>
  188. (function () {
  189. var b = Date.now();
  190. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  191. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  192. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  193. })();
  194. </script>
  195. <script>
  196. const CURRENT = 'layer/test_custom_animation.html';
  197. function switchTab(tab) {
  198. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  199. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  200. if (tab === 'js') {
  201. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  202. document.getElementById('js-code')?.classList.add('active');
  203. } else if (tab === 'html') {
  204. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  205. document.getElementById('html-code')?.classList.add('active');
  206. } else {
  207. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  208. document.getElementById('css-code')?.classList.add('active');
  209. }
  210. }
  211. function openDemo(name) {
  212. if (typeof window.$ !== 'function') return;
  213. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  214. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  215. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  216. const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
  217. const iconBox = name === 'loadding' ? '11em' : null;
  218. // Keep the displayed code consistent with what is executed.
  219. const code = `Layer.run({
  220. title: '${titleCap}',
  221. text: 'Lottie animation icon',
  222. icon: 'svg:${name}',
  223. iconAnimation: ${iconAnimation},
  224. popupAnimation: ${popupAnimation},
  225. closeOnEsc: ${closeOnEsc},
  226. iwidth: ${iconBox ? `'${iconBox}'` : 'null'},
  227. iheight: ${iconBox ? `'${iconBox}'` : 'null'}
  228. });`;
  229. const jsPre = document.getElementById('js-code');
  230. if (jsPre) {
  231. jsPre.textContent = code;
  232. // Re-run syntax highlight after content change.
  233. try { jsPre.dataset.highlighted = '0'; } catch {}
  234. try { if (window.__highlightCssViews) window.__highlightCssViews(); } catch {}
  235. }
  236. Layer.run({
  237. title: titleCap,
  238. text: 'Lottie animation icon',
  239. icon: 'svg:' + name,
  240. iconAnimation,
  241. popupAnimation,
  242. closeOnEsc,
  243. iwidth: iconBox,
  244. iheight: iconBox
  245. });
  246. }
  247. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  248. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  249. function syncNavLabels() {
  250. const api = window.parent?.docGetPrevNext;
  251. if (typeof api !== 'function') return;
  252. const { prev, next, current } = api(CURRENT) || {};
  253. const prevLink = document.getElementById('prevLink');
  254. const nextLink = document.getElementById('nextLink');
  255. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  256. else { prevLink.style.visibility = 'hidden'; }
  257. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  258. else { nextLink.style.visibility = 'hidden'; }
  259. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  260. }
  261. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  262. syncNavLabels();
  263. </script>
  264. </body>
  265. </html>