test_icons_svg_animation.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. <style>
  9. .controls {
  10. display: flex;
  11. flex-wrap: wrap;
  12. gap: 12px 16px;
  13. align-items: center;
  14. font-size: 13px;
  15. color: #b7b7b7;
  16. }
  17. .controls label {
  18. display: inline-flex;
  19. gap: 8px;
  20. align-items: center;
  21. cursor: pointer;
  22. user-select: none;
  23. }
  24. .controls input { accent-color: var(--highlight-color); }
  25. .row {
  26. display: flex;
  27. flex-wrap: wrap;
  28. gap: 10px;
  29. align-items: center;
  30. }
  31. .btn {
  32. appearance: none;
  33. border: 1px solid rgba(255,255,255,0.12);
  34. background: rgba(255,255,255,0.04);
  35. color: #fff;
  36. border-radius: 999px;
  37. padding: 10px 14px;
  38. font-weight: 650;
  39. cursor: pointer;
  40. transition: border-color 0.15s ease, background 0.15s ease;
  41. }
  42. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  43. .btn.success { border-color: rgba(165,220,134,0.55); background: rgba(165,220,134,0.12); }
  44. .btn.error { border-color: rgba(242,116,116,0.55); background: rgba(242,116,116,0.12); }
  45. .btn.warning { border-color: rgba(248,187,134,0.55); background: rgba(248,187,134,0.12); }
  46. .btn.info { border-color: rgba(63,195,238,0.55); background: rgba(63,195,238,0.12); }
  47. .demo-visual { padding: 22px 24px; }
  48. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  49. </style>
  50. </head>
  51. <body>
  52. <div class="container">
  53. <div class="page-top">
  54. <div class="crumb">UI › LAYER</div>
  55. <div class="since">ICON ANIMATION</div>
  56. </div>
  57. <h1>SVG Icon animation</h1>
  58. <p class="description">
  59. Uses <code class="inline">xjs.draw()</code> to animate the ring + mark strokes, and a spring entrance to mimic SweetAlert-like feedback.
  60. </p>
  61. <div class="box-container">
  62. <div class="box-header">
  63. <div class="box-title">Controls</div>
  64. <div class="tabs">
  65. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  66. <div class="tab" onclick="switchTab('html')">HTML</div>
  67. <div class="tab" onclick="switchTab('css')">CSS</div>
  68. </div>
  69. </div>
  70. <pre id="js-code" class="code-view active">xjs.layer({
  71. title: 'Success',
  72. text: 'SVG draw + spring',
  73. icon: 'success',
  74. iconAnimation: true,
  75. popupAnimation: true
  76. });</pre>
  77. <pre id="html-code" class="html-view">&lt;label&gt;&lt;input type="checkbox" checked&gt; iconAnimation&lt;/label&gt;
  78. &lt;label&gt;&lt;input type="checkbox" checked&gt; popupAnimation&lt;/label&gt;</pre>
  79. <pre id="css-code" class="css-view">/* Icon styling lives inside layer.js */</pre>
  80. <div class="feature-desc">
  81. <strong>功能说明:</strong>本页专门验证 Layer 的 icon 动画:描边(draw)+ 弹性缩放(spring)。你可以关闭其中任意一项来对比体验。
  82. </div>
  83. <div class="demo-visual">
  84. <div class="controls" style="margin-bottom: 14px;">
  85. <label><input id="optIcon" type="checkbox" checked> iconAnimation</label>
  86. <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
  87. <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
  88. </div>
  89. <div class="row">
  90. <button class="btn success" type="button" onclick="open('success')">Success</button>
  91. <button class="btn error" type="button" onclick="open('error')">Error</button>
  92. <button class="btn warning" type="button" onclick="open('warning')">Warning</button>
  93. <button class="btn info" type="button" onclick="open('info')">Info</button>
  94. <button class="btn" type="button" onclick="open('question')">Question</button>
  95. </div>
  96. <div class="hint">
  97. Tip: open “Error” to see the two stroke segments staggered.
  98. </div>
  99. </div>
  100. </div>
  101. <div class="doc-nav" aria-label="Previous and next navigation">
  102. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  103. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  104. <span aria-hidden="true">←</span>
  105. </a>
  106. <div class="nav-center" id="navCenter">Layer</div>
  107. <a href="#" id="nextLink" onclick="goNext(); return false;">
  108. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  109. <span aria-hidden="true">→</span>
  110. </a>
  111. </div>
  112. </div>
  113. <script src="../highlight_css.js"></script>
  114. <!-- NOTE: xjs.js bundles an older Layer in some builds.
  115. For local testing, load standalone layer.js last to ensure this page uses the edited Layer implementation. -->
  116. <script src="../../xjs.js?v=dev"></script>
  117. <script src="../../layer.js?v=dev"></script>
  118. <script>
  119. const CURRENT = 'layer/test_icons_svg_animation.html';
  120. // On-page error surface (helps debug inside iframe)
  121. (function () {
  122. const showErr = (title, detail) => {
  123. try {
  124. let el = document.getElementById('__err');
  125. if (!el) {
  126. el = document.createElement('div');
  127. el.id = '__err';
  128. el.style.position = 'fixed';
  129. el.style.left = '16px';
  130. el.style.right = '16px';
  131. el.style.bottom = '16px';
  132. el.style.zIndex = '999999';
  133. el.style.background = 'rgba(10,10,10,0.92)';
  134. el.style.border = '1px solid rgba(255,75,75,0.35)';
  135. el.style.borderRadius = '12px';
  136. el.style.padding = '10px 12px';
  137. el.style.color = '#ffd1d1';
  138. el.style.fontFamily = 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace';
  139. el.style.fontSize = '12px';
  140. el.style.whiteSpace = 'pre-wrap';
  141. el.style.maxHeight = '40vh';
  142. el.style.overflow = 'auto';
  143. document.body.appendChild(el);
  144. }
  145. el.textContent = `[${title}]\n` + String(detail || '');
  146. } catch {}
  147. };
  148. window.addEventListener('error', (e) => {
  149. showErr('error', e?.error?.stack || e?.message || e);
  150. });
  151. window.addEventListener('unhandledrejection', (e) => {
  152. showErr('unhandledrejection', e?.reason?.stack || e?.reason || e);
  153. });
  154. })();
  155. function switchTab(tab) {
  156. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  157. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  158. if (tab === 'js') {
  159. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  160. document.getElementById('js-code')?.classList.add('active');
  161. } else if (tab === 'html') {
  162. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  163. document.getElementById('html-code')?.classList.add('active');
  164. } else {
  165. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  166. document.getElementById('css-code')?.classList.add('active');
  167. }
  168. }
  169. function open(type) {
  170. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  171. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  172. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  173. // Defensive: if Layer failed to load, surface a useful error
  174. if (typeof xjs !== 'function') throw new Error('xjs is not loaded');
  175. if (!window.Layer) throw new Error('Layer is not loaded');
  176. return xjs.layer({
  177. title: type[0].toUpperCase() + type.slice(1),
  178. text: 'SVG draw + spring entrance',
  179. icon: type,
  180. iconAnimation,
  181. popupAnimation,
  182. closeOnEsc
  183. });
  184. }
  185. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  186. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  187. function syncNavLabels() {
  188. const api = window.parent?.docGetPrevNext;
  189. if (typeof api !== 'function') return;
  190. const { prev, next, current } = api(CURRENT) || {};
  191. const prevLink = document.getElementById('prevLink');
  192. const nextLink = document.getElementById('nextLink');
  193. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  194. else { prevLink.style.visibility = 'hidden'; }
  195. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  196. else { nextLink.style.visibility = 'hidden'; }
  197. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  198. }
  199. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  200. syncNavLabels();
  201. </script>
  202. </body>
  203. </html>