test_icons_svg_animation.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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">function openDemo(type) {
  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 title = String(type || '');
  98. const titleCap = title ? (title[0].toUpperCase() + title.slice(1)) : '';
  99. $.layer({
  100. title: titleCap,
  101. text: 'SVG draw + spring entrance',
  102. icon: title,
  103. iconAnimation,
  104. popupAnimation,
  105. closeOnEsc
  106. });
  107. }</pre>
  108. <pre id="html-code" class="html-view">&lt;div class="demo-visual"&gt;
  109. &lt;div class="controls" style="margin-bottom: 14px;"&gt;
  110. &lt;label&gt;&lt;input id="optIcon" type="checkbox" checked&gt; iconAnimation&lt;/label&gt;
  111. &lt;label&gt;&lt;input id="optPopup" type="checkbox" checked&gt; popupAnimation&lt;/label&gt;
  112. &lt;label&gt;&lt;input id="optEsc" type="checkbox" checked&gt; closeOnEsc&lt;/label&gt;
  113. &lt;/div&gt;
  114. &lt;div class="row"&gt;
  115. &lt;button class="btn success" type="button" onclick="openDemo('success')"&gt;Success&lt;/button&gt;
  116. &lt;button class="btn error" type="button" onclick="openDemo('error')"&gt;Error&lt;/button&gt;
  117. &lt;button class="btn warning" type="button" onclick="openDemo('warning')"&gt;Warning&lt;/button&gt;
  118. &lt;button class="btn info" type="button" onclick="openDemo('info')"&gt;Info&lt;/button&gt;
  119. &lt;button class="btn" type="button" onclick="openDemo('question')"&gt;Question&lt;/button&gt;
  120. &lt;/div&gt;
  121. &lt;div class="hint"&gt;
  122. Tip: open “Error” to see the two stroke segments staggered.
  123. &lt;/div&gt;
  124. &lt;/div&gt;</pre>
  125. <pre id="css-code" class="css-view">/* Keep Layer above the doc UI */
  126. .layer-overlay { z-index: 99999; }
  127. .controls {
  128. display: flex;
  129. flex-wrap: wrap;
  130. gap: 12px 16px;
  131. align-items: center;
  132. font-size: 13px;
  133. color: #b7b7b7;
  134. }
  135. .controls label {
  136. display: inline-flex;
  137. gap: 8px;
  138. align-items: center;
  139. cursor: pointer;
  140. user-select: none;
  141. }
  142. .controls input { accent-color: var(--highlight-color); }
  143. .row {
  144. display: flex;
  145. flex-wrap: wrap;
  146. gap: 10px;
  147. align-items: center;
  148. }
  149. .btn {
  150. appearance: none;
  151. border: 1px solid rgba(255,255,255,0.12);
  152. background: rgba(255,255,255,0.04);
  153. color: #fff;
  154. border-radius: 999px;
  155. padding: 10px 14px;
  156. font-weight: 650;
  157. cursor: pointer;
  158. transition: border-color 0.15s ease, background 0.15s ease;
  159. }
  160. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  161. .btn.success { border-color: rgba(165,220,134,0.55); background: rgba(165,220,134,0.12); }
  162. .btn.error { border-color: rgba(242,116,116,0.55); background: rgba(242,116,116,0.12); }
  163. .btn.warning { border-color: rgba(248,187,134,0.55); background: rgba(248,187,134,0.12); }
  164. .btn.info { border-color: rgba(63,195,238,0.55); background: rgba(63,195,238,0.12); }
  165. .demo-visual { padding: 22px 24px; }
  166. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }</pre>
  167. <div class="feature-desc">
  168. <strong>功能说明:</strong>本页专门验证 Layer 的 icon 动画:描边(draw)+ 弹性缩放(spring)。你可以关闭其中任意一项来对比体验。
  169. </div>
  170. </div>
  171. <div class="doc-nav" aria-label="Previous and next navigation">
  172. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  173. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  174. <span aria-hidden="true">←</span>
  175. </a>
  176. <div class="nav-center" id="navCenter">Layer</div>
  177. <a href="#" id="nextLink" onclick="goNext(); return false;">
  178. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  179. <span aria-hidden="true">→</span>
  180. </a>
  181. </div>
  182. </div>
  183. <script src="../highlight_css.js"></script>
  184. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  185. <script>
  186. (function () {
  187. var b = Date.now();
  188. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  189. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  190. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  191. })();
  192. </script>
  193. <script>
  194. const CURRENT = 'layer/test_icons_svg_animation.html';
  195. function switchTab(tab) {
  196. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  197. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  198. if (tab === 'js') {
  199. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  200. document.getElementById('js-code')?.classList.add('active');
  201. } else if (tab === 'html') {
  202. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  203. document.getElementById('html-code')?.classList.add('active');
  204. } else {
  205. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  206. document.getElementById('css-code')?.classList.add('active');
  207. }
  208. }
  209. // Small on-page debug panel (helps when running inside iframe)
  210. function __showDebug(title, detail) {
  211. try {
  212. let el = document.getElementById('__dbg');
  213. if (!el) {
  214. el = document.createElement('div');
  215. el.id = '__dbg';
  216. el.style.position = 'fixed';
  217. el.style.left = '16px';
  218. el.style.right = '16px';
  219. el.style.bottom = '16px';
  220. el.style.zIndex = '999999';
  221. el.style.background = 'rgba(10,10,10,0.92)';
  222. el.style.border = '1px solid rgba(255,255,255,0.18)';
  223. el.style.borderRadius = '12px';
  224. el.style.padding = '10px 12px';
  225. el.style.color = '#eaeaea';
  226. el.style.fontFamily = 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace';
  227. el.style.fontSize = '12px';
  228. el.style.whiteSpace = 'pre-wrap';
  229. el.style.maxHeight = '40vh';
  230. el.style.overflow = 'auto';
  231. document.body.appendChild(el);
  232. }
  233. el.textContent = `[${title}]\n` + String(detail || '');
  234. } catch {}
  235. }
  236. function __debugLayerDom() {
  237. try {
  238. const overlay = document.querySelector('.layer-overlay');
  239. const popup = document.querySelector('.layer-popup');
  240. const info = [];
  241. info.push(`overlay: ${overlay ? 'yes' : 'no'}`);
  242. info.push(`popup: ${popup ? 'yes' : 'no'}`);
  243. if (overlay) {
  244. const s = getComputedStyle(overlay);
  245. const r = overlay.getBoundingClientRect();
  246. info.push(`overlay display=${s.display} visibility=${s.visibility} opacity=${s.opacity} zIndex=${s.zIndex} bg=${s.backgroundColor}`);
  247. info.push(`overlay rect=${Math.round(r.width)}x${Math.round(r.height)} at (${Math.round(r.left)},${Math.round(r.top)})`);
  248. }
  249. if (popup) {
  250. const s = getComputedStyle(popup);
  251. const r = popup.getBoundingClientRect();
  252. info.push(`popup display=${s.display} visibility=${s.visibility} opacity=${s.opacity} zIndex=${s.zIndex} bg=${s.backgroundColor} color=${s.color}`);
  253. info.push(`popup transform=${s.transform}`);
  254. info.push(`popup rect=${Math.round(r.width)}x${Math.round(r.height)} at (${Math.round(r.left)},${Math.round(r.top)})`);
  255. info.push(`popup children=${popup.children.length}`);
  256. }
  257. __showDebug('layer debug', info.join('\n'));
  258. } catch (e) {
  259. __showDebug('layer debug error', e?.stack || e?.message || e);
  260. }
  261. }
  262. function openDemo(type) {
  263. if (typeof window.$ !== 'function') {
  264. __showDebug('xjs not ready', '$ is not available on window.');
  265. return;
  266. }
  267. const iconAnimation = !!document.getElementById('optIcon')?.checked;
  268. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  269. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  270. const title = String(type || '');
  271. const titleCap = title ? (title[0].toUpperCase() + title.slice(1)) : '';
  272. // Keep the displayed code consistent with what is executed.
  273. const code = `$.layer({
  274. title: '${titleCap}',
  275. text: 'SVG draw + spring entrance',
  276. icon: '${title}',
  277. iconAnimation: ${iconAnimation},
  278. popupAnimation: ${popupAnimation},
  279. closeOnEsc: ${closeOnEsc}
  280. });`;
  281. const jsPre = document.getElementById('js-code');
  282. if (jsPre) jsPre.textContent = code;
  283. try {
  284. $.layer({
  285. title: titleCap,
  286. text: 'SVG draw + spring entrance',
  287. icon: title,
  288. iconAnimation,
  289. popupAnimation,
  290. closeOnEsc
  291. });
  292. setTimeout(__debugLayerDom, 30);
  293. } catch (e) {
  294. __showDebug('openDemo error', e?.stack || e?.message || e);
  295. }
  296. }
  297. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  298. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  299. function syncNavLabels() {
  300. const api = window.parent?.docGetPrevNext;
  301. if (typeof api !== 'function') return;
  302. const { prev, next, current } = api(CURRENT) || {};
  303. const prevLink = document.getElementById('prevLink');
  304. const nextLink = document.getElementById('nextLink');
  305. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  306. else { prevLink.style.visibility = 'hidden'; }
  307. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  308. else { nextLink.style.visibility = 'hidden'; }
  309. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  310. }
  311. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  312. syncNavLabels();
  313. </script>
  314. </body>
  315. </html>