test_custom_animation_background.html 15 KB

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