test_custom_animation_background.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 背景动画 - 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. /* Allow larger widths for this demo */
  13. .layer-popup { max-width: none; }
  14. </style>
  15. <style>
  16. .controls {
  17. display: flex;
  18. flex-wrap: wrap;
  19. gap: 10px 12px;
  20. align-items: center;
  21. font-size: 13px;
  22. color: #b7b7b7;
  23. }
  24. .controls label {
  25. display: inline-flex;
  26. gap: 8px;
  27. align-items: center;
  28. cursor: pointer;
  29. user-select: none;
  30. }
  31. .controls input { accent-color: var(--highlight-color); }
  32. .row {
  33. display: flex;
  34. flex-wrap: wrap;
  35. gap: 10px;
  36. align-items: center;
  37. }
  38. .btn {
  39. appearance: none;
  40. border: 1px solid rgba(255,255,255,0.12);
  41. background: rgba(255,255,255,0.04);
  42. color: #fff;
  43. border-radius: 999px;
  44. padding: 10px 14px;
  45. font-weight: 650;
  46. cursor: pointer;
  47. transition: border-color 0.15s ease, background 0.15s ease;
  48. }
  49. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  50. .demo-visual { padding: 22px 24px; }
  51. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  52. .split { margin-top: 10px; width: 100%; height: 1px; background: rgba(255,255,255,0.08); }
  53. </style>
  54. </head>
  55. <body>
  56. <div class="container">
  57. <div class="page-top">
  58. <div class="crumb">UI › LAYER</div>
  59. <div class="since">BACKGROUND ANIMATION</div>
  60. </div>
  61. <h1>背景动画 / 背景图案</h1>
  62. <p class="description">
  63. 使用 <code class="inline">background</code> 设置 <code class="inline">layer-popup</code> 的整体背景,
  64. 支持三种形式:<code class="inline">svg(...)</code> / <code class="inline">url(...)</code> / <code class="inline">css(...)</code>。
  65. 在 Steps 模式下,当背景不同会随内容左右切换;相同背景则保持不动,仅切换内容。
  66. </p>
  67. <div class="box-container">
  68. <div class="demo-visual">
  69. <div class="controls" style="margin-bottom: 14px;">
  70. <label><input id="optIcon" type="checkbox" checked> showIcon</label>
  71. <label><input id="optPopup" type="checkbox" checked> popupAnimation</label>
  72. <label><input id="optEsc" type="checkbox" checked> closeOnEsc</label>
  73. </div>
  74. <div class="row">
  75. <button class="btn" type="button" onclick="openSingle('svg')">SVG 背景</button>
  76. <button class="btn" type="button" onclick="openSingle('image')">图片背景</button>
  77. <button class="btn" type="button" onclick="openSingle('css')">CSS 背景</button>
  78. </div>
  79. <div class="row" style="margin-top: 12px;">
  80. <button class="btn" type="button" onclick="openSingle('svg', 'compact')">SVG + 紧凑尺寸</button>
  81. <button class="btn" type="button" onclick="openSingle('image', 'wide')">图片 + 宽屏尺寸</button>
  82. <button class="btn" type="button" onclick="openSingle('css', 'tall')">CSS + 高屏尺寸</button>
  83. </div>
  84. <div class="split"></div>
  85. <div class="row" style="margin-top: 12px;">
  86. <button class="btn" type="button" onclick="openSteps('same')">Steps(相同背景)</button>
  87. <button class="btn" type="button" onclick="openSteps('diff')">Steps(不同背景)</button>
  88. </div>
  89. <div class="hint">
  90. Tip: Lottie 背景从 <code class="inline">/svg</code> 目录读取 JSON,示例为 <code class="inline">svg(BallSorting.json)</code>。
  91. </div>
  92. </div>
  93. <div class="box-header">
  94. <div class="box-title">Controls</div>
  95. <div class="tabs">
  96. <div class="tab active" onclick="switchTab('js')">JavaScript</div>
  97. <div class="tab" onclick="switchTab('html')">HTML</div>
  98. <div class="tab" onclick="switchTab('css')">CSS</div>
  99. </div>
  100. </div>
  101. <pre id="js-code" class="code-view active">const BACKGROUNDS = {
  102. svg: 'svg(BallSorting.json)',
  103. image: 'url("https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&amp;fit=crop&amp;w=900&amp;q=60")',
  104. css: 'css(background: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(0,0,0,0.25)); filter: saturate(1.2))'
  105. };
  106. const SIZE_PRESETS = {
  107. normal: null,
  108. compact: { width: 340, height: 220 },
  109. wide: { width: '60vw', height: 260 },
  110. tall: { width: 360, height: '60vh' }
  111. };
  112. function openSingle(type, sizeKey) {
  113. const showIcon = !!document.getElementById('optIcon')?.checked;
  114. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  115. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  116. const size = SIZE_PRESETS[sizeKey] || null;
  117. Layer.run({
  118. title: 'Background: ' + type.toUpperCase(),
  119. text: 'Layer popup background demo.',
  120. background: BACKGROUNDS[type],
  121. theme: 'light',
  122. width: size ? size.width : null,
  123. height: size ? size.height : null,
  124. icon: showIcon ? 'svg:BallSorting' : null,
  125. popupAnimation,
  126. closeOnEsc
  127. });
  128. }
  129. function openSteps(mode) {
  130. const showIcon = !!document.getElementById('optIcon')?.checked;
  131. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  132. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  133. const same = BACKGROUNDS.svg;
  134. const a = BACKGROUNDS.svg;
  135. const b = BACKGROUNDS.image;
  136. Layer.run({
  137. title: 'Step 1',
  138. text: 'Background should follow when different.',
  139. background: mode === 'same' ? same : a,
  140. theme: 'light',
  141. icon: showIcon ? 'info' : null,
  142. popupAnimation,
  143. closeOnEsc,
  144. showCancelButton: true
  145. })
  146. .step({
  147. title: 'Step 2',
  148. text: 'Swipe left/right to see background transition.',
  149. background: mode === 'same' ? same : b
  150. })
  151. .step({
  152. title: 'Step 3',
  153. text: 'Back to the first background.',
  154. background: mode === 'same' ? same : a
  155. })
  156. .run();
  157. }</pre>
  158. <pre id="html-code" class="html-view">&lt;div class="demo-visual"&gt;
  159. &lt;div class="controls" style="margin-bottom: 14px;"&gt;
  160. &lt;label&gt;&lt;input id="optIcon" type="checkbox" checked&gt; showIcon&lt;/label&gt;
  161. &lt;label&gt;&lt;input id="optPopup" type="checkbox" checked&gt; popupAnimation&lt;/label&gt;
  162. &lt;label&gt;&lt;input id="optEsc" type="checkbox" checked&gt; closeOnEsc&lt;/label&gt;
  163. &lt;/div&gt;
  164. &lt;div class="row"&gt;
  165. &lt;button class="btn" type="button" onclick="openSingle('svg')"&gt;SVG 背景&lt;/button&gt;
  166. &lt;button class="btn" type="button" onclick="openSingle('image')"&gt;图片背景&lt;/button&gt;
  167. &lt;button class="btn" type="button" onclick="openSingle('css')"&gt;CSS 背景&lt;/button&gt;
  168. &lt;/div&gt;
  169. &lt;div class="row" style="margin-top: 12px;"&gt;
  170. &lt;button class="btn" type="button" onclick="openSingle('svg', 'compact')"&gt;SVG + 紧凑尺寸&lt;/button&gt;
  171. &lt;button class="btn" type="button" onclick="openSingle('image', 'wide')"&gt;图片 + 宽屏尺寸&lt;/button&gt;
  172. &lt;button class="btn" type="button" onclick="openSingle('css', 'tall')"&gt;CSS + 高屏尺寸&lt;/button&gt;
  173. &lt;/div&gt;
  174. &lt;div class="split"&gt;&lt;/div&gt;
  175. &lt;div class="row" style="margin-top: 12px;"&gt;
  176. &lt;button class="btn" type="button" onclick="openSteps('same')"&gt;Steps(相同背景)&lt;/button&gt;
  177. &lt;button class="btn" type="button" onclick="openSteps('diff')"&gt;Steps(不同背景)&lt;/button&gt;
  178. &lt;/div&gt;
  179. &lt;/div&gt;</pre>
  180. <pre id="css-code" class="css-view">/* Keep Layer above the doc UI */
  181. .layer-overlay { z-index: 99999; }
  182. .controls {
  183. display: flex;
  184. flex-wrap: wrap;
  185. gap: 10px 12px;
  186. align-items: center;
  187. font-size: 13px;
  188. color: #b7b7b7;
  189. }
  190. .controls label {
  191. display: inline-flex;
  192. gap: 8px;
  193. align-items: center;
  194. cursor: pointer;
  195. user-select: none;
  196. }
  197. .controls input { accent-color: var(--highlight-color); }
  198. .row {
  199. display: flex;
  200. flex-wrap: wrap;
  201. gap: 10px;
  202. align-items: center;
  203. }
  204. .btn {
  205. appearance: none;
  206. border: 1px solid rgba(255,255,255,0.12);
  207. background: rgba(255,255,255,0.04);
  208. color: #fff;
  209. border-radius: 999px;
  210. padding: 10px 14px;
  211. font-weight: 650;
  212. cursor: pointer;
  213. transition: border-color 0.15s ease, background 0.15s ease;
  214. }
  215. .btn:hover { border-color: rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); }
  216. .demo-visual { padding: 22px 24px; }
  217. .hint { font-size: 12px; color: #8c8c8c; line-height: 1.5; margin-top: 10px; }
  218. .split { margin-top: 10px; width: 100%; height: 1px; background: rgba(255,255,255,0.08); }</pre>
  219. <div class="feature-desc">
  220. <strong>功能说明:</strong>本页验证 Layer 的 <code class="inline">background</code> 支持
  221. Lottie SVG / 图片 / CSS 三种形式,并在 Steps 中按方向切换背景。
  222. </div>
  223. </div>
  224. <div class="doc-nav" aria-label="Previous and next navigation">
  225. <a href="#" id="prevLink" onclick="goPrev(); return false;">
  226. <span><span class="nav-label">Previous</span><br><span class="nav-title" id="prevTitle">—</span></span>
  227. <span aria-hidden="true">←</span>
  228. </a>
  229. <div class="nav-center" id="navCenter">Layer</div>
  230. <a href="#" id="nextLink" onclick="goNext(); return false;">
  231. <span><span class="nav-label">Next</span><br><span class="nav-title" id="nextTitle">—</span></span>
  232. <span aria-hidden="true">→</span>
  233. </a>
  234. </div>
  235. </div>
  236. <script src="../highlight_css.js"></script>
  237. <!-- Dev/test: load source files directly with cache-bust (avoid stale iframe cache) -->
  238. <script>
  239. (function () {
  240. var b = Date.now();
  241. document.write('<script src="../../animal.js?_=' + b + '"><\/script>');
  242. document.write('<script src="../../layer.js?_=' + b + '"><\/script>');
  243. document.write('<script>try{if(window.animal&&!window.xjs)window.xjs=window.animal;}catch(e){}<\/script>');
  244. })();
  245. </script>
  246. <script>
  247. const CURRENT = 'layer/test_custom_animation_background.html';
  248. const BACKGROUNDS = {
  249. svg: 'svg(BallSorting.json)',
  250. image: 'url("https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?auto=format&fit=crop&w=900&q=60")',
  251. css: 'css(background: linear-gradient(135deg, rgba(255,255,255,0.15), rgba(0,0,0,0.25)); filter: saturate(1.2))'
  252. };
  253. const SIZE_PRESETS = {
  254. normal: null,
  255. compact: { width: 340, height: 220 },
  256. wide: { width: '60vw', height: 260 },
  257. tall: { width: 360, height: '60vh' }
  258. };
  259. function switchTab(tab) {
  260. document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
  261. document.querySelectorAll('.code-view, .html-view, .css-view').forEach(v => v.classList.remove('active'));
  262. if (tab === 'js') {
  263. document.querySelector('.tabs .tab:nth-child(1)')?.classList.add('active');
  264. document.getElementById('js-code')?.classList.add('active');
  265. } else if (tab === 'html') {
  266. document.querySelector('.tabs .tab:nth-child(2)')?.classList.add('active');
  267. document.getElementById('html-code')?.classList.add('active');
  268. } else {
  269. document.querySelector('.tabs .tab:nth-child(3)')?.classList.add('active');
  270. document.getElementById('css-code')?.classList.add('active');
  271. }
  272. }
  273. function setJsCode(code) {
  274. const jsPre = document.getElementById('js-code');
  275. if (!jsPre) return;
  276. jsPre.textContent = code;
  277. try { delete jsPre.dataset.highlighted; } catch {}
  278. try { jsPre.dataset.highlighted = '0'; } catch {}
  279. if (typeof window.__highlightCssViews === 'function') {
  280. window.__highlightCssViews();
  281. }
  282. }
  283. function openSingle(type, sizeKey) {
  284. if (typeof window.$ !== 'function') return;
  285. const showIcon = !!document.getElementById('optIcon')?.checked;
  286. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  287. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  288. const size = SIZE_PRESETS[sizeKey] || null;
  289. const code = `Layer.run({
  290. title: 'Background: ${type.toUpperCase()}',
  291. text: 'Layer popup background demo.',
  292. background: '${BACKGROUNDS[type]}',
  293. theme: 'light',
  294. width: ${size ? JSON.stringify(size.width) : 'null'},
  295. height: ${size ? JSON.stringify(size.height) : 'null'},
  296. icon: ${showIcon ? "'svg:BallSorting'" : 'null'},
  297. popupAnimation: ${popupAnimation},
  298. closeOnEsc: ${closeOnEsc}
  299. });`;
  300. setJsCode(code);
  301. Layer.run({
  302. title: 'Background: ' + type.toUpperCase(),
  303. text: 'Layer popup background demo.',
  304. background: BACKGROUNDS[type],
  305. theme: 'light',
  306. width: size ? size.width : null,
  307. height: size ? size.height : null,
  308. icon: showIcon ? 'svg:BallSorting' : null,
  309. popupAnimation,
  310. closeOnEsc
  311. });
  312. }
  313. function openSteps(mode) {
  314. if (typeof window.$ !== 'function') return;
  315. const showIcon = !!document.getElementById('optIcon')?.checked;
  316. const popupAnimation = !!document.getElementById('optPopup')?.checked;
  317. const closeOnEsc = !!document.getElementById('optEsc')?.checked;
  318. const same = BACKGROUNDS.svg;
  319. const a = BACKGROUNDS.svg;
  320. const b = BACKGROUNDS.image;
  321. const code = `Layer.$({
  322. theme: 'light',
  323. icon: ${showIcon ? "'info'" : 'null'},
  324. popupAnimation: ${popupAnimation},
  325. closeOnEsc: ${closeOnEsc},
  326. showCancelButton: true
  327. })
  328. .step({
  329. title: 'Step 1',
  330. text: 'Background should follow when different.',
  331. background: ${mode === 'same' ? 'same' : 'a'},
  332. width: '55em',
  333. height: '14em'
  334. })
  335. .step({
  336. title: 'Step 2',
  337. text: 'Swipe left/right to see background transition.',
  338. background: ${mode === 'same' ? 'same' : 'b'}
  339. })
  340. .step({
  341. title: 'Step 3',
  342. text: 'Back to the first background.',
  343. background: ${mode === 'same' ? 'same' : 'a'},
  344. width: '48em',
  345. height: '11em'
  346. })
  347. .run();`;
  348. setJsCode(code.replace(/\b(same|a|b)\b/g, (m) => {
  349. if (m === 'same') return `'${same}'`;
  350. if (m === 'a') return `'${a}'`;
  351. return `'${b}'`;
  352. }));
  353. Layer.$({
  354. theme: 'light',
  355. icon: showIcon ? 'info' : null,
  356. popupAnimation,
  357. closeOnEsc,
  358. showCancelButton: true
  359. })
  360. .step({
  361. title: 'Step 1',
  362. text: 'Background should follow when different.',
  363. background: mode === 'same' ? same : a,
  364. width: '55em',
  365. height: '14em'
  366. })
  367. .step({
  368. title: 'Step 2',
  369. text: 'Swipe left/right to see background transition.',
  370. background: mode === 'same' ? same : b
  371. })
  372. .step({
  373. title: 'Step 3',
  374. text: 'Back to the first background.',
  375. background: mode === 'same' ? same : a,
  376. width: '48em',
  377. height: '11em'
  378. })
  379. .run();
  380. }
  381. function goPrev() { window.parent?.docNavigatePrev?.(CURRENT); }
  382. function goNext() { window.parent?.docNavigateNext?.(CURRENT); }
  383. function syncNavLabels() {
  384. const api = window.parent?.docGetPrevNext;
  385. if (typeof api !== 'function') return;
  386. const { prev, next, current } = api(CURRENT) || {};
  387. const prevLink = document.getElementById('prevLink');
  388. const nextLink = document.getElementById('nextLink');
  389. if (prev) document.getElementById('prevTitle').textContent = prev.title || prev.url;
  390. else { prevLink.style.visibility = 'hidden'; }
  391. if (next) document.getElementById('nextTitle').textContent = next.title || next.url;
  392. else { nextLink.style.visibility = 'hidden'; }
  393. document.getElementById('navCenter').textContent = (current && current.group) ? current.group : 'Layer';
  394. }
  395. try { window.parent?.setMiddleActive?.(CURRENT); } catch {}
  396. syncNavLabels();
  397. </script>
  398. </body>
  399. </html>