test_custom_animation.html 9.9 KB

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