test_custom_animation_background.html 15 KB

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