test_icons_svg_animation.html 11 KB

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