test_custom_animation.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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" type="button" onclick="openDemo('BallSorting', false)">Scale Pop</button>
  79. <button class="btn disabled" type="button" disabled>更多动画待加入...</button>
  80. </div>
  81. <div class="hint">
  82. Tip: 关闭 <code class="inline">popupAnimation</code> 可查看当前位置的缩放回弹效果。
  83. </div>
  84. </div>
  85. <div class="box-header">
  86. <div class="box-title">Controls</div>
  87. <div class="tabs">
  88. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  89. <div class="tab" onclick="switchTab('html')">HTML</div>
  90. <div class="tab" onclick="switchTab('css')">CSS</div>
  91. </div>
  92. </div>
  93. <pre id="js-code" class="code-view active">function openDemo(name, popupOverride) {
  94. if (typeof window.$ !== 'function') return;
  95. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  96. const popupAnimation = (typeof popupOverride === 'boolean')
  97. ? popupOverride
  98. : !!document.getElementById('optPopup')?.checked;
  99. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  100. const iconBox = name === 'loadding' ? '11em' : null;
  101. const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
  102. Layer.run({
  103. title: titleCap,
  104. text: 'Lottie animation icon',
  105. icon: 'svg:' + name,
  106. iconAnimation,
  107. popupAnimation,
  108. closeOnEsc,
  109. iwidth: iconBox,
  110. iheight: iconBox
  111. });
  112. }</pre>
  113. <pre id="html-code" class="html-view">&lt;div class="demo-visual"&gt;
  114. &lt;div class="controls" style="margin-bottom: 14px;"&gt;
  115. &lt;label&gt;&lt;input id="optIcon" type="checkbox" checked&gt; iconAnimation&lt;/label&gt;
  116. &lt;label&gt;&lt;input id="optPopup" type="checkbox" checked&gt; popupAnimation&lt;/label&gt;
  117. &lt;label&gt;&lt;input id="optEsc" type="checkbox" checked&gt; closeOnEsc&lt;/label&gt;
  118. &lt;/div&gt;
  119. &lt;div class="row"&gt;
  120. &lt;button class="btn" type="button" onclick="openDemo('loadding')"&gt;Loading&lt;/button&gt;
  121. &lt;button class="btn" type="button" onclick="openDemo('banner')"&gt;Banner&lt;/button&gt;
  122. &lt;button class="btn" type="button" onclick="openDemo('BallSorting')"&gt;BallSorting&lt;/button&gt;
  123. &lt;button class="btn" type="button" onclick="openDemo('BallSorting', false)"&gt;Scale Pop&lt;/button&gt;
  124. &lt;button class="btn disabled" type="button" disabled&gt;更多动画待加入...&lt;/button&gt;
  125. &lt;/div&gt;
  126. &lt;div class="hint"&gt;
  127. Tip: 关闭 &lt;code class="inline"&gt;popupAnimation&lt;/code&gt; 可查看当前位置的缩放回弹效果。
  128. &lt;/div&gt;
  129. &lt;/div&gt;</pre>
  130. <pre id="css-code" class="css-view">/* Keep Layer above the doc UI */
  131. .layer-overlay { z-index: 99999; }
  132. .controls {
  133. display: flex;
  134. flex-wrap: wrap;
  135. gap: 10px 12px;
  136. align-items: center;
  137. font-size: 13px;
  138. color: #b7b7b7;
  139. }
  140. .controls label {
  141. display: inline-flex;
  142. gap: 8px;
  143. align-items: center;
  144. cursor: pointer;
  145. user-select: none;
  146. }
  147. .controls input { accent-color: var(--highlight-color); }
  148. .row {
  149. display: flex;
  150. flex-wrap: wrap;
  151. gap: 10px;
  152. align-items: center;
  153. }
  154. .btn {
  155. appearance: none;
  156. border: 1px solid rgba(255,255,255,0.12);
  157. background: rgba(255,255,255,0.04);
  158. color: #fff;
  159. border-radius: 999px;
  160. padding: 10px 14px;
  161. font-weight: 650;
  162. cursor: pointer;
  163. transition: border-color 0.15s ease, background 0.15s ease;
  164. }
  165. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  166. .btn.disabled {
  167. opacity: 0.5;
  168. cursor: not-allowed;
  169. }
  170. .demo-visual { padding: 22px 24px; }
  171. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }</pre>
  172. <div class="feature-desc">
  173. <strong>功能说明:</strong>本页验证 Layer 在 <code class="inline">icon</code> 传入 <code class="inline">svg:</code> 前缀时,
  174. 会自动加载 Lottie 库并渲染对应 JSON 动画。
  175. </div>
  176. </div>
  177. <div class="doc-nav" aria-label="Previous and next navigation">
  178. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  179. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  180. <span aria-hidden="true">←</span>
  181. </a>
  182. <div class="nav-center" id="navCenter">Layer</div>
  183. <a href="#" id="nextLink" onclick="goNext(); return false;">
  184. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  185. <span aria-hidden="true">→</span>
  186. </a>
  187. </div>
  188. </div>
  189. <script src="../highlight_css.js"></script>
  190. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  191. <script>
  192. (function () {
  193. var b = Date.now();
  194. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  195. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  196. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  197. })();
  198. </script>
  199. <script>
  200. const CURRENT = 'layer/test_custom_animation.html';
  201. function switchTab(tab) {
  202. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  203. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  204. if (tab === 'js') {
  205. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  206. document.getElementById('js-code')?.classList.add('active');
  207. } else if (tab === 'html') {
  208. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  209. document.getElementById('html-code')?.classList.add('active');
  210. } else {
  211. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  212. document.getElementById('css-code')?.classList.add('active');
  213. }
  214. }
  215. function openDemo(name, popupOverride) {
  216. if (typeof window.$ !== 'function') return;
  217. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  218. const popupAnimation = (typeof popupOverride === 'boolean')
  219. ? popupOverride
  220. : !!document.getElementById('optPopup')?.checked;
  221. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  222. const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
  223. const iconBox = name === 'loadding' ? '11em' : null;
  224. // Keep the displayed code consistent with what is executed.
  225. const code = `Layer.run({
  226. title: '${titleCap}',
  227. text: 'Lottie animation icon',
  228. icon: 'svg:${name}',
  229. iconAnimation: ${iconAnimation},
  230. popupAnimation: ${popupAnimation},
  231. closeOnEsc: ${closeOnEsc},
  232. iwidth: ${iconBox ? `'${iconBox}'` : 'null'},
  233. iheight: ${iconBox ? `'${iconBox}'` : 'null'}
  234. });`;
  235. const jsPre = document.getElementById('js-code');
  236. if (jsPre) {
  237. jsPre.textContent = code;
  238. // Re-run syntax highlight after content change.
  239. try { jsPre.dataset.highlighted = '0'; } catch {}
  240. try { if (window.__highlightCssViews) window.__highlightCssViews(); } catch {}
  241. }
  242. Layer.run({
  243. title: titleCap,
  244. text: 'Lottie animation icon',
  245. icon: 'svg:' + name,
  246. iconAnimation,
  247. popupAnimation,
  248. closeOnEsc,
  249. iwidth: iconBox,
  250. iheight: iconBox
  251. });
  252. }
  253. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  254. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  255. function syncNavLabels() {
  256. const api = window.parent?.docGetPrevNext;
  257. if (typeof api !== 'function') return;
  258. const { prev, next, current } = api(CURRENT) || {};
  259. const prevLink = document.getElementById('prevLink');
  260. const nextLink = document.getElementById('nextLink');
  261. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  262. else { prevLink.style.visibility = 'hidden'; }
  263. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  264. else { nextLink.style.visibility = 'hidden'; }
  265. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  266. }
  267. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  268. syncNavLabels();
  269. </script>
  270. </body>
  271. </html>