test_custom_animation_banner.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 自定义动画(Banner)- 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. .demo-visual { padding: 22px 24px; }
  49. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="container">
  54. <div class="page-top">
  55. <div class="crumb">UI › LAYER</div>
  56. <div class="since">CUSTOM ANIMATION</div>
  57. </div>
  58. <h1>自定义动画(Banner)</h1>
  59. <p class="description">
  60. 使用 <code class="inline">icon: "svg:banner"</code> 渲染 <code class="inline">svg/banner.json</code>。
  61. </p>
  62. <div class="box-container">
  63. <div class="demo-visual">
  64. <div class="controls" style="margin-bottom: 14px;">
  65. <label><input id="optIcon" type="checkbox" checked> iconAnimation</label>
  66. <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
  67. <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
  68. </div>
  69. <div class="row">
  70. <button class="btn" type="button" onclick="openDemo('banner')">Open Banner</button>
  71. </div>
  72. <div class="hint">
  73. Tip: <code class="inline">banner.json</code> 位于 <code class="inline">/svg</code> 目录。
  74. </div>
  75. </div>
  76. <div class="box-header">
  77. <div class="box-title">Controls</div>
  78. <div class="tabs">
  79. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  80. <div class="tab" onclick="switchTab('html')">HTML</div>
  81. <div class="tab" onclick="switchTab('css')">CSS</div>
  82. </div>
  83. </div>
  84. <pre id="js-code" class="code-view active">function openDemo(name) {
  85. if (typeof window.$ !== 'function') return;
  86. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  87. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  88. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  89. const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
  90. $.layer({
  91. title: titleCap,
  92. text: 'Lottie animation icon',
  93. icon: 'svg:' + name,
  94. iconAnimation,
  95. popupAnimation,
  96. closeOnEsc
  97. });
  98. }</pre>
  99. <pre id="html-code" class="html-view">&lt;div class="demo-visual"&gt;
  100. &lt;div class="controls" style="margin-bottom: 14px;"&gt;
  101. &lt;label&gt;&lt;input id="optIcon" type="checkbox" checked&gt; iconAnimation&lt;/label&gt;
  102. &lt;label&gt;&lt;input id="optPopup" type="checkbox" checked&gt; popupAnimation&lt;/label&gt;
  103. &lt;label&gt;&lt;input id="optEsc" type="checkbox" checked&gt; closeOnEsc&lt;/label&gt;
  104. &lt;/div&gt;
  105. &lt;div class="row"&gt;
  106. &lt;button class="btn" type="button" onclick="openDemo('banner')"&gt;Open Banner&lt;/button&gt;
  107. &lt;/div&gt;
  108. &lt;div class="hint"&gt;
  109. Tip: &lt;code class="inline"&gt;banner.json&lt;/code&gt; 位于 &lt;code class="inline"&gt;/svg&lt;/code&gt; 目录。
  110. &lt;/div&gt;
  111. &lt;/div&gt;</pre>
  112. <pre id="css-code" class="css-view">/* Keep Layer above the doc UI */
  113. .layer-overlay { z-index: 99999; }
  114. .controls {
  115. display: flex;
  116. flex-wrap: wrap;
  117. gap: 10px 12px;
  118. align-items: center;
  119. font-size: 13px;
  120. color: #b7b7b7;
  121. }
  122. .controls label {
  123. display: inline-flex;
  124. gap: 8px;
  125. align-items: center;
  126. cursor: pointer;
  127. user-select: none;
  128. }
  129. .controls input { accent-color: var(--highlight-color); }
  130. .row {
  131. display: flex;
  132. flex-wrap: wrap;
  133. gap: 10px;
  134. align-items: center;
  135. }
  136. .btn {
  137. appearance: none;
  138. border: 1px solid rgba(255,255,255,0.12);
  139. background: rgba(255,255,255,0.04);
  140. color: #fff;
  141. border-radius: 999px;
  142. padding: 10px 14px;
  143. font-weight: 650;
  144. cursor: pointer;
  145. transition: border-color 0.15s ease, background 0.15s ease;
  146. }
  147. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  148. .demo-visual { padding: 22px 24px; }
  149. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }</pre>
  150. <div class="feature-desc">
  151. <strong>功能说明:</strong>本页验证 Layer 在 <code class="inline">icon</code> 传入 <code class="inline">svg:banner</code> 时,
  152. 会自动加载 Lottie 库并渲染 <code class="inline">banner.json</code>。
  153. </div>
  154. </div>
  155. <div class="doc-nav" aria-label="Previous and next navigation">
  156. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  157. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  158. <span aria-hidden="true">←</span>
  159. </a>
  160. <div class="nav-center" id="navCenter">Layer</div>
  161. <a href="#" id="nextLink" onclick="goNext(); return false;">
  162. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  163. <span aria-hidden="true">→</span>
  164. </a>
  165. </div>
  166. </div>
  167. <script src="../highlight_css.js"></script>
  168. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  169. <script>
  170. (function () {
  171. var b = Date.now();
  172. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  173. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  174. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  175. })();
  176. </script>
  177. <script>
  178. const CURRENT = 'layer/test_custom_animation_banner.html';
  179. function switchTab(tab) {
  180. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  181. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  182. if (tab === 'js') {
  183. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  184. document.getElementById('js-code')?.classList.add('active');
  185. } else if (tab === 'html') {
  186. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  187. document.getElementById('html-code')?.classList.add('active');
  188. } else {
  189. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  190. document.getElementById('css-code')?.classList.add('active');
  191. }
  192. }
  193. function openDemo(name) {
  194. if (typeof window.$ !== 'function') return;
  195. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  196. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  197. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  198. const titleCap = name ? (name[0].toUpperCase() + name.slice(1)) : '';
  199. // Keep the displayed code consistent with what is executed.
  200. const code = `$.layer({
  201. title: '${titleCap}',
  202. text: 'Lottie animation icon',
  203. icon: 'svg:${name}',
  204. iconAnimation: ${iconAnimation},
  205. popupAnimation: ${popupAnimation},
  206. closeOnEsc: ${closeOnEsc}
  207. });`;
  208. const jsPre = document.getElementById('js-code');
  209. if (jsPre) jsPre.textContent = code;
  210. $.layer({
  211. title: titleCap,
  212. text: 'Lottie animation icon',
  213. icon: 'svg:' + name,
  214. iconAnimation,
  215. popupAnimation,
  216. closeOnEsc
  217. });
  218. }
  219. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  220. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  221. function syncNavLabels() {
  222. const api = window.parent?.docGetPrevNext;
  223. if (typeof api !== 'function') return;
  224. const { prev, next, current } = api(CURRENT) || {};
  225. const prevLink = document.getElementById('prevLink');
  226. const nextLink = document.getElementById('nextLink');
  227. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  228. else { prevLink.style.visibility = 'hidden'; }
  229. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  230. else { nextLink.style.visibility = 'hidden'; }
  231. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  232. }
  233. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  234. syncNavLabels();
  235. </script>
  236. </body>
  237. </html>