test_icons_svg_animation.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 SVG Icon Animation - Animal.js</title>
  7. <link rel="stylesheet" href="../demo.css">
  8. <link rel="stylesheet" href="../../xjs.css?v=2">
  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: 12px 16px;
  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.success { border-color: rgba(165,220,134,0.55); background: rgba(165,220,134,0.12); }
  49. .btn.error { border-color: rgba(242,116,116,0.55); background: rgba(242,116,116,0.12); }
  50. .btn.warning { border-color: rgba(248,187,134,0.55); background: rgba(248,187,134,0.12); }
  51. .btn.info { border-color: rgba(63,195,238,0.55); background: rgba(63,195,238,0.12); }
  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">ICON ANIMATION</div>
  61. </div>
  62. <h1>SVG Icon animation</h1>
  63. <p class="description">
  64. Uses <code class="inline">xjs.draw()</code> to animate the ring + mark strokes, and a spring entrance to mimic SweetAlert-like feedback.
  65. </p>
  66. <div class="box-container">
  67. <div class="box-header">
  68. <div class="box-title">Controls</div>
  69. <div class="tabs">
  70. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  71. <div class="tab" onclick="switchTab('html')">HTML</div>
  72. <div class="tab" onclick="switchTab('css')">CSS</div>
  73. </div>
  74. </div>
  75. <pre id="js-code" class="code-view active">xjs.layer({
  76. title: 'Success',
  77. text: 'SVG draw + spring entrance',
  78. icon: 'success',
  79. iconAnimation: true,
  80. popupAnimation: true,
  81. closeOnEsc: true
  82. });</pre>
  83. <pre id="html-code" class="html-view">&lt;label&gt;&lt;input id="optIcon" type="checkbox" checked&gt; iconAnimation&lt;/label&gt;
  84. &lt;label&gt;&lt;input id="optPopup" type="checkbox" checked&gt; popupAnimation&lt;/label&gt;
  85. &lt;label&gt;&lt;input id="optEsc" type="checkbox" checked&gt; closeOnEsc&lt;/label&gt;
  86. &lt;button class="btn success" type="button" onclick="openDemo('success')"&gt;Success&lt;/button&gt;
  87. &lt;button class="btn error" type="button" onclick="openDemo('error')"&gt;Error&lt;/button&gt;
  88. &lt;button class="btn warning" type="button" onclick="openDemo('warning')"&gt;Warning&lt;/button&gt;
  89. &lt;button class="btn info" type="button" onclick="openDemo('info')"&gt;Info&lt;/button&gt;
  90. &lt;button class="btn" type="button" onclick="openDemo('question')"&gt;Question&lt;/button&gt;</pre>
  91. <pre id="css-code" class="css-view">/* Icon styling lives inside layer.js */</pre>
  92. <div class="feature-desc">
  93. <strong>功能说明:</strong>本页专门验证 Layer 的 icon 动画:描边(draw)+ 弹性缩放(spring)。你可以关闭其中任意一项来对比体验。
  94. </div>
  95. <div class="demo-visual">
  96. <div class="controls" style="margin-bottom: 14px;">
  97. <label><input id="optIcon" type="checkbox" checked> iconAnimation</label>
  98. <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
  99. <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
  100. </div>
  101. <div class="row">
  102. <button class="btn success" type="button" onclick="openDemo('success')">Success</button>
  103. <button class="btn error" type="button" onclick="openDemo('error')">Error</button>
  104. <button class="btn warning" type="button" onclick="openDemo('warning')">Warning</button>
  105. <button class="btn info" type="button" onclick="openDemo('info')">Info</button>
  106. <button class="btn" type="button" onclick="openDemo('question')">Question</button>
  107. </div>
  108. <div class="hint">
  109. Tip: open “Error” to see the two stroke segments staggered.
  110. </div>
  111. </div>
  112. </div>
  113. <div class="doc-nav" aria-label="Previous and next navigation">
  114. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  115. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  116. <span aria-hidden="true">←</span>
  117. </a>
  118. <div class="nav-center" id="navCenter">Layer</div>
  119. <a href="#" id="nextLink" onclick="goNext(); return false;">
  120. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  121. <span aria-hidden="true">→</span>
  122. </a>
  123. </div>
  124. </div>
  125. <script src="../highlight_css.js"></script>
  126. <!-- Dev/test: load source files directly (sync, avoids async loader timing) -->
  127. <script src="../../animal.js?v=dev"></script>
  128. <script src="../../layer.js?v=dev"></script>
  129. <script>
  130. // Ensure global alias
  131. if (window.animal && !window.xjs) window.xjs = window.animal;
  132. </script>
  133. <script>
  134. const CURRENT = 'layer/test_icons_svg_animation.html';
  135. function switchTab(tab) {
  136. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  137. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  138. if (tab === 'js') {
  139. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  140. document.getElementById('js-code')?.classList.add('active');
  141. } else if (tab === 'html') {
  142. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  143. document.getElementById('html-code')?.classList.add('active');
  144. } else {
  145. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  146. document.getElementById('css-code')?.classList.add('active');
  147. }
  148. }
  149. // Small on-page debug panel (helps when running inside iframe)
  150. function __showDebug(title, detail) {
  151. try {
  152. let el = document.getElementById('__dbg');
  153. if (!el) {
  154. el = document.createElement('div');
  155. el.id = '__dbg';
  156. el.style.position = 'fixed';
  157. el.style.left = '16px';
  158. el.style.right = '16px';
  159. el.style.bottom = '16px';
  160. el.style.zIndex = '999999';
  161. el.style.background = 'rgba(10,10,10,0.92)';
  162. el.style.border = '1px solid rgba(255,255,255,0.18)';
  163. el.style.borderRadius = '12px';
  164. el.style.padding = '10px 12px';
  165. el.style.color = '#eaeaea';
  166. el.style.fontFamily = 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace';
  167. el.style.fontSize = '12px';
  168. el.style.whiteSpace = 'pre-wrap';
  169. el.style.maxHeight = '40vh';
  170. el.style.overflow = 'auto';
  171. document.body.appendChild(el);
  172. }
  173. el.textContent = `[${title}]\n` + String(detail || '');
  174. } catch {}
  175. }
  176. function __debugLayerDom() {
  177. try {
  178. const overlay = document.querySelector('.layer-overlay');
  179. const popup = document.querySelector('.layer-popup');
  180. const info = [];
  181. info.push(`overlay: ${overlay ? 'yes' : 'no'}`);
  182. info.push(`popup: ${popup ? 'yes' : 'no'}`);
  183. if (overlay) {
  184. const s = getComputedStyle(overlay);
  185. const r = overlay.getBoundingClientRect();
  186. info.push(`overlay display=${s.display} visibility=${s.visibility} opacity=${s.opacity} zIndex=${s.zIndex} bg=${s.backgroundColor}`);
  187. info.push(`overlay rect=${Math.round(r.width)}x${Math.round(r.height)} at (${Math.round(r.left)},${Math.round(r.top)})`);
  188. }
  189. if (popup) {
  190. const s = getComputedStyle(popup);
  191. const r = popup.getBoundingClientRect();
  192. info.push(`popup display=${s.display} visibility=${s.visibility} opacity=${s.opacity} zIndex=${s.zIndex} bg=${s.backgroundColor} color=${s.color}`);
  193. info.push(`popup transform=${s.transform}`);
  194. info.push(`popup rect=${Math.round(r.width)}x${Math.round(r.height)} at (${Math.round(r.left)},${Math.round(r.top)})`);
  195. info.push(`popup children=${popup.children.length}`);
  196. }
  197. __showDebug('layer debug', info.join('\n'));
  198. } catch (e) {
  199. __showDebug('layer debug error', e?.stack || e?.message || e);
  200. }
  201. }
  202. function openDemo(type) {
  203. const X = window.xjs || window.animal;
  204. if (typeof X !== 'function') {
  205. __showDebug('xjs not ready', 'animal.js not loaded or xjs alias missing.');
  206. return;
  207. }
  208. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  209. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  210. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  211. const title = String(type || '');
  212. const titleCap = title ? (title[0].toUpperCase() + title.slice(1)) : '';
  213. // Keep the displayed code consistent with what is executed.
  214. const code = `xjs.layer({
  215. title: '${titleCap}',
  216. text: 'SVG draw + spring entrance',
  217. icon: '${title}',
  218. iconAnimation: ${iconAnimation},
  219. popupAnimation: ${popupAnimation},
  220. closeOnEsc: ${closeOnEsc}
  221. });`;
  222. const jsPre = document.getElementById('js-code');
  223. if (jsPre) jsPre.textContent = code;
  224. try {
  225. X.layer({
  226. title: titleCap,
  227. text: 'SVG draw + spring entrance',
  228. icon: title,
  229. iconAnimation,
  230. popupAnimation,
  231. closeOnEsc
  232. });
  233. setTimeout(__debugLayerDom, 30);
  234. } catch (e) {
  235. __showDebug('openDemo error', e?.stack || e?.message || e);
  236. }
  237. }
  238. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  239. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  240. function syncNavLabels() {
  241. const api = window.parent?.docGetPrevNext;
  242. if (typeof api !== 'function') return;
  243. const { prev, next, current } = api(CURRENT) || {};
  244. const prevLink = document.getElementById('prevLink');
  245. const nextLink = document.getElementById('nextLink');
  246. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  247. else { prevLink.style.visibility = 'hidden'; }
  248. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  249. else { nextLink.style.visibility = 'hidden'; }
  250. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  251. }
  252. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  253. syncNavLabels();
  254. </script>
  255. </body>
  256. </html>