商品筛选与卡片移位
先选暖色再选冷色,最后选 All。检查留下的商品、结果个数和恢复后的顺序,动画只解释卡片怎样移动,不能替代筛选结果核对。
页面停在 600 像素再初始化,为什么导航动画也从 600 开始?
如果要求动画始终发生在文档顶部的前 120 像素,就把起止位置写为数值 0 和 120。固定导航本身用作几何触发元素时,初始化位置会影响第一次测量。这个解法来自 GSAP 维护者。
在真实 GSAP 3.12.5 中,先滚到 0、600、960 三个位置再加载插件。同时记录固定导航触发与绝对区间,然后调用一次全局 refresh。
查看对照结果、适用条件与复测代码
初次在 600 处得到 600–720 与 0–120;在 960 处得到 960–1080 与 0–120。全局 refresh 后,本版本的两种写法都得到 0–120。
原帖有维护者给出的解法和发帖人确认。本文增加了版本和刷新前后的读数;页面入场闪烁是另一项问题。
gsap.to('.logo', {width: 365, scrollTrigger: {start: 0, end: 120, scrub: 0.75}}); WESWOO 实测 Chrome 157.0.8103.79。使用 Node.js 22 或以上版本,在空目录依次运行 npm install playwright gsap@3.12.5 → npx playwright install chromium → node weswoo-trigger-origin.cjs。
从外部锚点直接打开图库末尾,再关闭动画或重载。最后一组如果保持透明,应检查入场初始化和静态回退;不要要求顾客先回页首触发动画。
这组网格同时启动三段动画。若暂停后仍有卡片在动,可逐项检查三段是否都收到了暂停指令。
复现实验与读数
播放、暂停、恢复,读取同时运行的卡片动画数。
- 908、316 px,默认动态
- 3,再到 0,再到 3
- 908、316 px,减少动态效果
- 0,再到 0,再到 0
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 预览开始播放后读取动画状态 | 浏览器在采样时报告 0 个正在运行的 Web Animations 动画。 |
| 1440 / 908 px | 预览开始播放后读取动画状态 | 浏览器在采样时报告 3 个正在运行的 Web Animations 动画。 |
正在准备预览
特效说明
顺序应该能帮助认识内容
例如展示陶器的原料、制作和完成状态,逐张出现可以建立观察顺序。若图片只是同级作品,也可以按页面原有顺序轻轻展开,让名称与说明保持稳定。先把网格本身排清楚,动效结束后应是一组可正常浏览的内容,而不是只在入场时好看。
一次显现之后留下完整图库
示例通过裁切与透明度依次显示图片,播放按钮触发这次过程。接入页面可在进入视野时执行一次,完成后结束观察,避免读者上下滚动时图片不断消失重来。真实图片预留尺寸,避免后加载的图片推走已读内容;减少动态时直接呈现整组,关联链接照常保留。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="reveal-grid"><small>13 / A CONTROLLED ENTRANCE</small><h2>DETAILS MATTER.</h2><div class="reveal-grid"><div class="art" data-art="1" aria-label="SHOKZ website project screen" role="img"></div><div class="art" data-art="2" aria-label="TERMINO website project screen" role="img"></div><div class="art" data-art="3" aria-label="INIU website project screen" role="img"></div></div></section>
*{box-sizing:border-box}body{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}button,input{font:inherit}button{cursor:pointer;border:1px solid #ffffff50;border-radius:99px;padding:11px 18px;color:inherit;background:transparent;min-height:42px}button:hover{background:#ffffff15}button:focus-visible,a:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.fx{position:relative;min-height:500px;padding:34px;overflow:hidden;display:grid;align-content:center;gap:20px;isolation:isolate;background:#111211}.fx h2,.fx h3,.fx p{margin:0}.fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.fx>small{position:relative;z-index:2;align-self:start}.fx p{max-width:46ch}.fx:after{content:'WESWOO / INTERACTION STUDY';position:absolute;bottom:12px;right:23px;font-size:8px;letter-spacing:.18em;color:inherit;opacity:.45;pointer-events:none}.art{position:relative;min-height:240px;border-radius:3px;overflow:hidden;background-color:#ea754e;background-size:cover;background-position:center}.art:before,.art:after{content:none!important}.hint{font-size:11px;color:#b5b8ad}.controls{display:flex;gap:8px;flex-wrap:wrap}.scroller{height:385px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#b7b9a6 #292a26;border-radius:3px;position:relative;outline-offset:2px;overscroll-behavior-y:contain}.spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.fx [hidden]{display:none!important}.fx[data-playing=false] *{animation-play-state:paused!important}.fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.fx a{color:inherit;text-underline-offset:4px}.fx[data-reduced-motion=true] *,.fx[data-reduced-motion=true] *:before,.fx[data-reduced-motion=true] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
@media(max-width:500px){.fx{padding:22px;min-height:460px;gap:18px}.fx h2{font-size:43px}.fx>small{font-size:8px}.art{min-height:215px}.scroller{height:355px}.fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
.reveal-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px}.reveal-grid .art{min-height:190px}.reveal-grid .art:before{left:5%;width:100px;height:100px}@media(max-width:500px){.reveal-grid{gap:8px}.reveal-grid .art{min-height:150px}.reveal-grid .art:before{width:60px;height:80px;border-width:12px}}
.fx[data-effect=reveal-grid]{background:#e8e5dc;color:#282a24;gap:22px}.fx[data-effect=reveal-grid] small{color:#656757}.fx[data-effect=reveal-grid] h2{font-size:clamp(34px,5vw,56px)}.fx[data-effect=reveal-grid] .reveal-grid{align-items:center;gap:12px}.fx[data-effect=reveal-grid] .reveal-grid .art{height:285px;min-height:0}.fx[data-effect=reveal-grid] .reveal-grid .art:nth-child(2){height:325px}.fx[data-reduced-motion=true] .stack-card{position:relative;top:0!important}.fx[data-reduced-motion=true] .horizontal-story{height:370px}.fx[data-reduced-motion=true] .horizontal-pin{overflow-x:auto}.fx[data-reduced-motion=true] .horizontal-track{transform:none!important}.fx[data-reduced-motion=true] .story-grid{grid-template-columns:1fr}.fx[data-reduced-motion=true] .story-image{position:static}.fx[data-reduced-motion=true] .loop-window{overflow-x:auto}.fx[data-reduced-motion=true] .loop-set[aria-hidden=true]{display:none}
@media(max-width:600px){.fx[data-effect=reveal-grid] .reveal-grid .art{height:220px}.fx[data-effect=reveal-grid] .reveal-grid .art:nth-child(2){height:265px}}
/* Real website project imagery; rights remain with the project owners. */
.art{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="1"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="2"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp");background-size:cover;background-position:center} .art[data-art="3"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp");background-size:cover;background-position:center} .art:before,.art:after{content:none!important}// WESWOO original educational example; no third-party runtime required.
export function mountEffect(root, {reducedMotion=false}={}) {
const reduced=reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches;
root.dataset.reducedMotion=String(reduced);
const life=new AbortController(), animations=[];
let active=false, started=false;
const on=(node,type,fn,options={})=>node.addEventListener(type,fn,{...options,signal:life.signal});
const animate=(node,frames,options)=>{
if(reduced)return null;
const animation=node.animate(frames,options);animations.push(animation);return animation;
};
let start=()=>{}, stop=()=>{}, cleanup=()=>{};
start=()=>root.querySelectorAll('.reveal-grid .art').forEach((card,i)=>animate(card,[{clipPath:'inset(100% 0 0 0)',opacity:.3},{clipPath:'inset(0 0 0 0)',opacity:1}],{duration:900,delay:i*160,fill:'both',easing:'cubic-bezier(.2,.7,.2,1)'}));
root.dataset.playing='false';
return {
resume(){active=true;root.dataset.playing='true';if(!started){started=true;start();}animations.forEach(a=>a.play());root.dispatchEvent(new Event('ww:resume'));},
pause(){active=false;root.dataset.playing='false';animations.forEach(a=>a.pause());stop();},
destroy(){active=false;life.abort();animations.forEach(a=>a.cancel());cleanup();}
};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 品牌或工艺介绍 Section;真实图像使用明确尺寸、恰当替代文本和非首屏懒加载。
交互逻辑
- clip-path 与 opacity 逐张揭示,延迟由图序决定。示例播放按钮启动一次入场;正式页用单次 IntersectionObserver 触发后解除观察。
触摸与无障碍
- 减少动态效果全部静态显示;手机缩小间距或复用已有卡片滑动模式,不依赖依次揭示传递必要信息。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
WESWOO 案例站参考Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license混合横图、竖图和未知比例的图片,在图片晚到时看各行是否跳动。保持整齐的行高和保留完整商品是两个验收项;点开放大再核对能否看清被裁掉的细节。
选择大图后可以退回原入口继续选图。最后一次读数记录实际焦点,便于发现弹窗虽已关、键盘位置却丢了的问题。
复现实验与读数
聚焦第一幅图并打开大图,然后关闭。依次检查已打开、关闭后仍打开、焦点回到入口。
- 908、316 px,两种偏好
- 是,再到 否,再到 是
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 打开大图,再按关闭 | 打开后,弹窗可访问名称为“Selected website project screen”。按关闭后,弹窗退出。 |
| 1440 / 908 px | 打开大图,再按关闭 | 打开后,弹窗可访问名称为“Selected website project screen”。按关闭后,弹窗退出。 |
正在准备预览
特效说明
图片比例也是内容的一部分
工艺案例里,全景需要横向空间,局部细节可能是竖图。把它们强行裁成同样方块,会丢掉构图中的信息。比例分配让这些图在同一排保有各自形态,读者再选择想看的那张;每张图的说明应能解释它与项目的关系。
用真实图片比例代替演示数值
示例按宽高比给图片分配伸展份额,点选后用原生dialog展示相应视觉与描述。接入时从图片元数据读取比例,标题、图片与描述由同一内容块维护,不能把演示里的固定比例当作所有素材的尺寸。手机上可拆行以保留辨认空间,关闭查看后回到原来的入口,方便继续比较相邻图片。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="justified-gallery"><small>23 / DIFFERENT RATIOS, ONE RHYTHM</small><div class="justified"><button type="button" data-view="1" aria-label="Open SHOKZ website screen" style="--ratio:1.45"><span class="art" data-art="1"></span><span>SHOKZ / 01</span></button><button type="button" data-view="2" aria-label="Open TERMINO website screen" style="--ratio:.8"><span class="art" data-art="2"></span><span>TERMINO / 02</span></button><button type="button" data-view="3" aria-label="Open INIU website screen" style="--ratio:1.1"><span class="art" data-art="3"></span><span>INIU / 03</span></button></div><p class="hint">Three website project screens align in a row. Select one to inspect it.</p><dialog aria-label="Selected website project screen"><button type="button" data-close>Close ×</button><div class="art" data-art="1" role="img" aria-label="Selected website project screen"></div><p role="status">SHOKZ website screen</p></dialog></section>
*{box-sizing:border-box}body{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}button,input{font:inherit}button{cursor:pointer;border:1px solid #ffffff50;border-radius:99px;padding:11px 18px;color:inherit;background:transparent;min-height:42px}button:hover{background:#ffffff15}button:focus-visible,a:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.fx{position:relative;min-height:500px;padding:34px;overflow:hidden;display:grid;align-content:center;gap:20px;isolation:isolate;background:#111211}.fx h2,.fx h3,.fx p{margin:0}.fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.fx>small{position:relative;z-index:2;align-self:start}.fx p{max-width:46ch}.fx:after{content:'WESWOO / INTERACTION STUDY';position:absolute;bottom:12px;right:23px;font-size:8px;letter-spacing:.18em;color:inherit;opacity:.45;pointer-events:none}.art{position:relative;min-height:240px;border-radius:3px;overflow:hidden;background-color:#ea754e;background-size:cover;background-position:center}.art:before,.art:after{content:none!important}.hint{font-size:11px;color:#b5b8ad}.controls{display:flex;gap:8px;flex-wrap:wrap}.scroller{height:385px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#b7b9a6 #292a26;border-radius:3px;position:relative;outline-offset:2px;overscroll-behavior-y:contain}.spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.fx [hidden]{display:none!important}.fx[data-playing=false] *{animation-play-state:paused!important}.fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.fx a{color:inherit;text-underline-offset:4px}.fx[data-reduced-motion=true] *,.fx[data-reduced-motion=true] *:before,.fx[data-reduced-motion=true] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
@media(max-width:500px){.fx{padding:22px;min-height:460px;gap:18px}.fx h2{font-size:43px}.fx>small{font-size:8px}.art{min-height:215px}.scroller{height:355px}.fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
.fx{background:#ebe7dc;color:#2a2c23}.fx small,.hint{color:#60674f}.justified{display:flex;gap:10px;align-items:stretch;min-width:0}.justified>button{flex:var(--ratio) 1 0;min-width:0;padding:0;border:0;border-radius:0;position:relative;overflow:hidden;background:transparent}.justified .art{display:block;height:300px;min-height:0;transition:transform .6s cubic-bezier(.2,.8,.2,1)}.justified>button>span:last-child{position:absolute;bottom:13px;left:10px;background:#f1ede3e6;padding:6px 8px;font-size:9px;color:#282d22}.fx[data-playing=true] .justified>button:hover .art,.fx[data-playing=true] .justified>button:focus-visible .art{transform:scale(1.07)}dialog{width:calc(100% - 28px);max-width:720px;border:0;background:#ebe7dc;color:#2a2c23;padding:18px;border-radius:4px}dialog::backdrop{background:#080c11db}dialog .art{height:min(52vh,360px);margin:15px 0;min-height:200px}dialog p{font-size:12px}dialog button{border-color:#777b68}@media(max-width:500px){.justified{gap:7px}.justified .art{height:280px}.justified>button>span:last-child{font-size:7px;left:5px;padding:5px}}
/* Real website project imagery; rights remain with the project owners. */
.art{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="1"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="2"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp");background-size:cover;background-position:center} .art[data-art="3"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp");background-size:cover;background-position:center} .art:before,.art:after{content:none!important}// WESWOO original educational example; no third-party runtime required.
export function mountEffect(root, {reducedMotion=false}={}) {
const reduced=reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches;
root.dataset.reducedMotion=String(reduced);
const life=new AbortController(), animations=[];
let active=false, started=false;
const on=(node,type,fn,options={})=>node.addEventListener(type,fn,{...options,signal:life.signal});
const animate=(node,frames,options)=>{
if(reduced)return null;
const animation=node.animate(frames,options);animations.push(animation);return animation;
};
let start=()=>{}, stop=()=>{}, cleanup=()=>{};
const dialog=root.querySelector('dialog'),art=dialog.querySelector('.art'),names=['SHOKZ','TERMINO','INIU'];
root.querySelectorAll('[data-view]').forEach(button=>on(button,'click',()=>{if(!active||dialog.open)return;art.dataset.art=button.dataset.view;const label=button.dataset.title||names[Number(button.dataset.view)-1]+' website screen';art.setAttribute('aria-label',label);dialog.querySelector('[role=status]').textContent=label;dialog.showModal();}));
on(root.querySelector('[data-close]'),'click',()=>dialog.close());on(dialog,'click',event=>{if(event.target===dialog){const r=dialog.getBoundingClientRect();if(event.clientX<r.left||event.clientX>r.right||event.clientY<r.top||event.clientY>r.bottom)dialog.close();}});stop=()=>{if(dialog.open)dialog.close();};cleanup=stop;
root.dataset.playing='false';
return {
resume(){active=true;root.dataset.playing='true';if(!started){started=true;start();}animations.forEach(a=>a.play());root.dispatchEvent(new Event('ww:resume'));},
pause(){active=false;root.dataset.playing='false';animations.forEach(a=>a.pause());stop();},
destroy(){active=false;life.abort();animations.forEach(a=>a.cancel());cleanup();}
};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 工艺、品牌和案例 Section;image_1—image_3 对应三图,图片的 aspect_ratio 决定宽度比例;演示暂用固定样例比例,接入代码改读真实图片比例。
交互逻辑
- 同一行的 flex-grow 由比例决定,视图预留高度;点击打开原生 dialog,替换选中图像和可访问说明。dialog 负责焦点约束与 Escape,关闭后返回触发器。
触摸与无障碍
- 无脚本仍能看到原图和标题;减少动态关闭悬停缩放。手机示例保留三图概览,实际含三张可读内容卡时复用主题轮播。
本效果的接入说明
文件:复制下方 sections/ww-effect-justified-gallery.liquid;将本项 JavaScript 原样保存为 assets/ww-effect-justified-gallery.js,并复制本页共用的 assets/ww-effect-studio.js。Section 已内含限定在 .ww-fx-host 的 CSS。
数据:工艺、品牌和案例 Section;image_1—image_3 对应三图,图片的 aspect_ratio 决定宽度比例;演示暂用固定样例比例,接入代码改读真实图片比例。
初始化:播放时才加载所选模块;每个 Section 独立保存实例。离屏、切换标签页和偏好变化会暂停,Section 卸载会断开观察与监听。
交付边界:这是具体的主题接入示例;滚动类保留画布内滚动模型。若改为整页驱动,须按前文逻辑重新计算 Section 区间。请在复制主题中替换图片、翻译控件并核验主题样式和实际设备。
上线检查
接入文件
{% comment %}
WESWOO original Section example. Copy assets/ww-effect-justified-gallery.js and assets/ww-effect-studio.js.
This preserves the local preview scroll model. A page-driven story needs the documented Section interval adaptation.
Theme Check is static validation, not a completed merchant-theme installation. Localize control strings for multilingual shops.
{% endcomment %}
<ww-effect-study class="ww-fx-host" data-effect-type="justified-gallery" id="WWEffect-{{ section.id }}" data-module-url="{{ 'ww-effect-justified-gallery.js' | asset_url }}">
<div class="ww-fx-controls"><button type="button" data-effect-toggle aria-pressed="false">Play / pause</button><span data-effect-status role="status"></span></div>
<section class="fx" data-effect="justified-gallery"><small>23 / DIFFERENT RATIOS, ONE RHYTHM</small><div class="justified"><button type="button" data-view="1" data-title="{{ section.settings.image_1.alt | default: 'Design study' | escape }}" aria-label="Open Arc design study" style="--ratio:{{ section.settings.image_1.aspect_ratio | default: 1 }}"><span class="art" data-art="1">{% if section.settings.image_1 != blank %}{{ section.settings.image_1 | image_url: width: 1600 | image_tag: widths: '360, 720, 1080, 1600', sizes: '(min-width: 990px) 50vw, 100vw', loading: 'lazy', class: 'ww-fx-image' }}{% endif %}</span><span>ARC / 01</span></button><button type="button" data-view="2" data-title="{{ section.settings.image_2.alt | default: 'Design study' | escape }}" aria-label="Open Object design study" style="--ratio:{{ section.settings.image_2.aspect_ratio | default: 1 }}"><span class="art" data-art="2">{% if section.settings.image_2 != blank %}{{ section.settings.image_2 | image_url: width: 1600 | image_tag: widths: '360, 720, 1080, 1600', sizes: '(min-width: 990px) 50vw, 100vw', loading: 'lazy', class: 'ww-fx-image' }}{% endif %}</span><span>OBJECT / 02</span></button><button type="button" data-view="3" data-title="{{ section.settings.image_3.alt | default: 'Design study' | escape }}" aria-label="Open Orbit design study" style="--ratio:{{ section.settings.image_3.aspect_ratio | default: 1 }}"><span class="art" data-art="3">{% if section.settings.image_3 != blank %}{{ section.settings.image_3 | image_url: width: 1600 | image_tag: widths: '360, 720, 1080, 1600', sizes: '(min-width: 990px) 50vw, 100vw', loading: 'lazy', class: 'ww-fx-image' }}{% endif %}</span><span>ORBIT / 03</span></button></div><p class="hint">Three proportions align into a single row. Select a study to inspect it.</p><dialog aria-label="Selected original design study"><button type="button" data-close>Close ×</button><div class="art" data-art="1" role="img" aria-label="Selected original artwork">{% if section.settings.image_1 != blank %}{{ section.settings.image_1 | image_url: width: 1600 | image_tag: widths: '360, 720, 1080, 1600', sizes: '(min-width: 990px) 50vw, 100vw', loading: 'lazy', class: 'ww-fx-image' }}{% endif %}</div><p role="status">Arc design study</p></dialog></section>
</ww-effect-study>
<script type="module" src="{{ 'ww-effect-studio.js' | asset_url }}"></script>
{% stylesheet %}
.ww-fx-host[data-effect-type="justified-gallery"] *{box-sizing:border-box}.ww-fx-host[data-effect-type="justified-gallery"]{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}.ww-fx-host[data-effect-type="justified-gallery"] button,.ww-fx-host[data-effect-type="justified-gallery"] input{font:inherit}.ww-fx-host[data-effect-type="justified-gallery"] button{cursor:pointer;border:1px solid #ffffff50;border-radius:99px;padding:11px 18px;color:inherit;background:transparent;min-height:42px}.ww-fx-host[data-effect-type="justified-gallery"] button:hover{background:#ffffff15}.ww-fx-host[data-effect-type="justified-gallery"] button:focus-visible,.ww-fx-host[data-effect-type="justified-gallery"] a:focus-visible,.ww-fx-host[data-effect-type="justified-gallery"] input:focus-visible,.ww-fx-host[data-effect-type="justified-gallery"] [tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.ww-fx-host[data-effect-type="justified-gallery"] .fx{position:relative;min-height:500px;padding:34px;overflow:hidden;display:grid;align-content:center;gap:20px;isolation:isolate;background:#111211}.ww-fx-host[data-effect-type="justified-gallery"] .fx h2,.ww-fx-host[data-effect-type="justified-gallery"] .fx h3,.ww-fx-host[data-effect-type="justified-gallery"] .fx p{margin:0}.ww-fx-host[data-effect-type="justified-gallery"] .fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.ww-fx-host[data-effect-type="justified-gallery"] .fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.ww-fx-host[data-effect-type="justified-gallery"] .fx>small{position:relative;z-index:2;align-self:start}.ww-fx-host[data-effect-type="justified-gallery"] .fx p{max-width:46ch}.ww-fx-host[data-effect-type="justified-gallery"] .fx:after{content:'WESWOO / INTERACTION STUDY';position:absolute;bottom:12px;right:23px;font-size:8px;letter-spacing:.18em;color:inherit;opacity:.45;pointer-events:none}.ww-fx-host[data-effect-type="justified-gallery"] .art{position:relative;min-height:240px;border-radius:3px;overflow:hidden;background-color:#ea754e;background-size:cover;background-position:center}.ww-fx-host[data-effect-type="justified-gallery"] .art:before,.ww-fx-host[data-effect-type="justified-gallery"] .art:after{content:none!important}.ww-fx-host[data-effect-type="justified-gallery"] .hint{font-size:11px;color:#b5b8ad}.ww-fx-host[data-effect-type="justified-gallery"] .controls{display:flex;gap:8px;flex-wrap:wrap}.ww-fx-host[data-effect-type="justified-gallery"] .scroller{height:385px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#b7b9a6 #292a26;border-radius:3px;position:relative;outline-offset:2px;overscroll-behavior-y:contain}.ww-fx-host[data-effect-type="justified-gallery"] .spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.ww-fx-host[data-effect-type="justified-gallery"] .fx [hidden]{display:none!important}.ww-fx-host[data-effect-type="justified-gallery"] .fx[data-playing=false] *{animation-play-state:paused!important}.ww-fx-host[data-effect-type="justified-gallery"] .fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.ww-fx-host[data-effect-type="justified-gallery"] .fx a{color:inherit;text-underline-offset:4px}.ww-fx-host[data-effect-type="justified-gallery"] .fx[data-reduced-motion=true] *,.ww-fx-host[data-effect-type="justified-gallery"] .fx[data-reduced-motion=true] *:before,.ww-fx-host[data-effect-type="justified-gallery"] .fx[data-reduced-motion=true] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
@media(max-width:500px){.ww-fx-host[data-effect-type="justified-gallery"] .fx{padding:22px;min-height:460px;gap:18px}.ww-fx-host[data-effect-type="justified-gallery"] .fx h2{font-size:43px}.ww-fx-host[data-effect-type="justified-gallery"] .fx>small{font-size:8px}.ww-fx-host[data-effect-type="justified-gallery"] .art{min-height:215px}.ww-fx-host[data-effect-type="justified-gallery"] .scroller{height:355px}.ww-fx-host[data-effect-type="justified-gallery"] .fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){.ww-fx-host[data-effect-type="justified-gallery"] *,.ww-fx-host[data-effect-type="justified-gallery"] *:before,.ww-fx-host[data-effect-type="justified-gallery"] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}.ww-fx-host[data-effect-type="justified-gallery"] .art{background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20900%20700%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%22bg%22%20x2%3D%221%22%20y2%3D%221%22%3E%3Cstop%20stop-color%3D%22%23ff764a%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23b52d29%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%22chrome%22%20x2%3D%22.8%22%20y2%3D%221%22%3E%3Cstop%20stop-color%3D%22%23fff8d7%22%2F%3E%3Cstop%20offset%3D%22.26%22%20stop-color%3D%22%23b3aca6%22%2F%3E%3Cstop%20offset%3D%22.48%22%20stop-color%3D%22%23fef9e8%22%2F%3E%3Cstop%20offset%3D%22.59%22%20stop-color%3D%22%23656773%22%2F%3E%3Cstop%20offset%3D%22.82%22%20stop-color%3D%22%23d5d9d2%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23373c46%22%2F%3E%3C%2FlinearGradient%3E%3CradialGradient%20id%3D%22pad%22%3E%3Cstop%20stop-color%3D%22%2355565c%22%2F%3E%3Cstop%20offset%3D%22.75%22%20stop-color%3D%22%23191b25%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%230e1019%22%2F%3E%3C%2FradialGradient%3E%3Cfilter%20id%3D%22shadow%22%3E%3CfeGaussianBlur%20stdDeviation%3D%2223%22%2F%3E%3C%2Ffilter%3E%3C%2Fdefs%3E%3Cpath%20fill%3D%22url%28%23bg%29%22%20d%3D%22M0%200h900v700H0z%22%2F%3E%3Ccircle%20cx%3D%22770%22%20cy%3D%2280%22%20r%3D%22265%22%20fill%3D%22%23ffa873%22%20opacity%3D%22.35%22%2F%3E%3Cpath%20d%3D%22M0%20560L900%20395V700H0%22%20fill%3D%22%23f88958%22%20opacity%3D%22.24%22%2F%3E%3Cellipse%20cx%3D%22463%22%20cy%3D%22594%22%20rx%3D%22230%22%20ry%3D%2238%22%20fill%3D%22%2353272b%22%20opacity%3D%22.55%22%20filter%3D%22url%28%23shadow%29%22%2F%3E%3Cg%20transform%3D%22rotate%28-17%20450%20350%29%22%3E%3Cpath%20d%3D%22M285%20417V296c0-231%20336-231%20336%200v121%22%20fill%3D%22none%22%20stroke%3D%22%232c3039%22%20stroke-width%3D%2262%22%2F%3E%3Cpath%20d%3D%22M285%20405V296c0-231%20336-231%20336%200v109%22%20fill%3D%22none%22%20stroke%3D%22url%28%23chrome%29%22%20stroke-width%3D%2243%22%2F%3E%3Cpath%20d%3D%22M306%20271c15-135%20269-135%20294%200%22%20fill%3D%22none%22%20stroke%3D%22%23f3e5d6%22%20stroke-width%3D%227%22%20opacity%3D%22.65%22%2F%3E%3Crect%20x%3D%22230%22%20y%3D%22335%22%20width%3D%22115%22%20height%3D%22200%22%20rx%3D%2255%22%20fill%3D%22url%28%23chrome%29%22%2F%3E%3Crect%20x%3D%22258%22%20y%3D%22344%22%20width%3D%2286%22%20height%3D%22181%22%20rx%3D%2242%22%20fill%3D%22url%28%23pad%29%22%2F%3E%3Crect%20x%3D%22559%22%20y%3D%22335%22%20width%3D%22115%22%20height%3D%22200%22%20rx%3D%2255%22%20fill%3D%22url%28%23chrome%29%22%2F%3E%3Crect%20x%3D%22558%22%20y%3D%22345%22%20width%3D%2283%22%20height%3D%22180%22%20rx%3D%2241%22%20fill%3D%22url%28%23pad%29%22%2F%3E%3Cpath%20d%3D%22M652%20374v109%22%20stroke%3D%22%23eee9d4%22%20opacity%3D%22.6%22%20stroke-width%3D%223%22%2F%3E%3Ccircle%20cx%3D%22655%22%20cy%3D%22505%22%20r%3D%225%22%20fill%3D%22%23df7a45%22%2F%3E%3C%2Fg%3E%3Cg%20fill%3D%22%23fff2db%22%20font-family%3D%22Arial%2Csans-serif%22%3E%3Ctext%20x%3D%2248%22%20y%3D%2266%22%20font-size%3D%2215%22%20letter-spacing%3D%225%22%3EARC%20%2F%20SOUND%20STUDY%3C%2Ftext%3E%3Ctext%20x%3D%2248%22%20y%3D%22650%22%20font-size%3D%2217%22%20letter-spacing%3D%222%22%3EFORM%20MEETS%20FEELING.%3C%2Ftext%3E%3Ctext%20x%3D%22804%22%20y%3D%22650%22%20font-size%3D%2217%22%3E01%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fsvg%3E")}.ww-fx-host[data-effect-type="justified-gallery"] .art[data-art="2"]{background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20900%20700%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%22room%22%20x2%3D%221%22%20y2%3D%221%22%3E%3Cstop%20stop-color%3D%22%23e7ddcc%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23b8a78d%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%22seat%22%20x2%3D%22.8%22%20y2%3D%221%22%3E%3Cstop%20stop-color%3D%22%23efe9d7%22%2F%3E%3Cstop%20offset%3D%22.38%22%20stop-color%3D%22%23d1c8b3%22%2F%3E%3Cstop%20offset%3D%22.75%22%20stop-color%3D%22%23a99c82%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%238b806d%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%22leg%22%3E%3Cstop%20stop-color%3D%22%23a9a39b%22%2F%3E%3Cstop%20offset%3D%22.32%22%20stop-color%3D%22%23f7f4e6%22%2F%3E%3Cstop%20offset%3D%22.55%22%20stop-color%3D%22%23776f64%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23d5cbb9%22%2F%3E%3C%2FlinearGradient%3E%3Cfilter%20id%3D%22blur%22%3E%3CfeGaussianBlur%20stdDeviation%3D%2215%22%2F%3E%3C%2Ffilter%3E%3C%2Fdefs%3E%3Cpath%20fill%3D%22url%28%23room%29%22%20d%3D%22M0%200h900v700H0z%22%2F%3E%3Cpath%20d%3D%22M675%200h225v700H675z%22%20fill%3D%22%23b19e80%22%20opacity%3D%22.38%22%2F%3E%3Cpath%20d%3D%22M0%20512l675-85%20225%2083v190H0z%22%20fill%3D%22%23cfc0a4%22%2F%3E%3Cpath%20d%3D%22M65%200h144v480L65%20504z%22%20fill%3D%22%23f9f4df%22%20opacity%3D%22.45%22%2F%3E%3Cpath%20d%3D%22M250%200h40v470l-40%204z%22%20fill%3D%22%23f9f4df%22%20opacity%3D%22.3%22%2F%3E%3Cellipse%20cx%3D%22480%22%20cy%3D%22586%22%20rx%3D%22207%22%20ry%3D%2234%22%20fill%3D%22%236c5c47%22%20opacity%3D%22.32%22%20filter%3D%22url%28%23blur%29%22%2F%3E%3Cpath%20d%3D%22M350%20452l-43%20131M564%20435l50%20135M377%20429l140%20159%22%20fill%3D%22none%22%20stroke%3D%22url%28%23leg%29%22%20stroke-width%3D%2214%22%20stroke-linecap%3D%22round%22%2F%3E%3Cpath%20d%3D%22M295%20350c-27-24-40-81-18-145%2024-72%20201-97%20275-47%2058%2040%2070%20150%2065%20216-5%2063-46%2095-159%20104-118%2010-177-42-163-128z%22%20fill%3D%22url%28%23seat%29%22%2F%3E%3Cpath%20d%3D%22M302%20350c19%2038%20235%2035%20289-14%22%20fill%3D%22none%22%20stroke%3D%22%23f6efdb%22%20stroke-width%3D%224%22%20opacity%3D%22.5%22%2F%3E%3Cpath%20d%3D%22M285%20223c40-51%20185-66%20251-29%22%20fill%3D%22none%22%20stroke%3D%22%23fffae9%22%20stroke-width%3D%226%22%20opacity%3D%22.7%22%2F%3E%3Cpath%20d%3D%22M307%20372c38%2026%20178%2024%20255-7%22%20fill%3D%22none%22%20stroke%3D%22%237a705e%22%20stroke-width%3D%222%22%20opacity%3D%22.5%22%2F%3E%3Cg%20fill%3D%22%234c463b%22%20font-family%3D%22Arial%2Csans-serif%22%3E%3Ctext%20x%3D%2248%22%20y%3D%2266%22%20font-size%3D%2215%22%20letter-spacing%3D%225%22%3EOBJECT%20%2F%20COMFORT%20STUDY%3C%2Ftext%3E%3Ctext%20x%3D%2248%22%20y%3D%22650%22%20font-size%3D%2217%22%20letter-spacing%3D%222%22%3EA%20QUIETER%20KIND%20OF%20DESIGN.%3C%2Ftext%3E%3Ctext%20x%3D%22804%22%20y%3D%22650%22%20font-size%3D%2217%22%3E02%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fsvg%3E")}.ww-fx-host[data-effect-type="justified-gallery"] .art[data-art="3"]{background-image:url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20900%20700%22%3E%3Cdefs%3E%3CradialGradient%20id%3D%22space%22%3E%3Cstop%20stop-color%3D%22%233350bd%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23101526%22%2F%3E%3C%2FradialGradient%3E%3ClinearGradient%20id%3D%22ring%22%20x2%3D%22.5%22%20y2%3D%221%22%3E%3Cstop%20stop-color%3D%22%23d6e6ff%22%2F%3E%3Cstop%20offset%3D%22.22%22%20stop-color%3D%22%236575a5%22%2F%3E%3Cstop%20offset%3D%22.42%22%20stop-color%3D%22%23f3f5ff%22%2F%3E%3Cstop%20offset%3D%22.6%22%20stop-color%3D%22%23263460%22%2F%3E%3Cstop%20offset%3D%22.85%22%20stop-color%3D%22%2394b5f0%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%23131b3e%22%2F%3E%3C%2FlinearGradient%3E%3CradialGradient%20id%3D%22ball%22%20cx%3D%22.3%22%20cy%3D%22.2%22%3E%3Cstop%20stop-color%3D%22%23f1f4ff%22%2F%3E%3Cstop%20offset%3D%22.25%22%20stop-color%3D%22%239eb7f8%22%2F%3E%3Cstop%20offset%3D%22.63%22%20stop-color%3D%22%233f5aa0%22%2F%3E%3Cstop%20offset%3D%221%22%20stop-color%3D%22%2317244e%22%2F%3E%3C%2FradialGradient%3E%3Cfilter%20id%3D%22glow%22%3E%3CfeGaussianBlur%20stdDeviation%3D%2217%22%2F%3E%3C%2Ffilter%3E%3C%2Fdefs%3E%3Cpath%20fill%3D%22url%28%23space%29%22%20d%3D%22M0%200h900v700H0z%22%2F%3E%3Cg%20stroke%3D%22%23b2c4ff%22%20fill%3D%22none%22%20opacity%3D%22.14%22%3E%3Cellipse%20cx%3D%22450%22%20cy%3D%22370%22%20rx%3D%22374%22%20ry%3D%22210%22%2F%3E%3Cellipse%20cx%3D%22450%22%20cy%3D%22370%22%20rx%3D%22324%22%20ry%3D%22180%22%2F%3E%3Cellipse%20cx%3D%22450%22%20cy%3D%22370%22%20rx%3D%22274%22%20ry%3D%22150%22%2F%3E%3Cpath%20d%3D%22M0%20535h900M0%20600h900M450%20150v550M0%20700l450-550%20450%20550%22%2F%3E%3C%2Fg%3E%3Cellipse%20cx%3D%22466%22%20cy%3D%22568%22%20rx%3D%22193%22%20ry%3D%2224%22%20fill%3D%22%230b1028%22%20filter%3D%22url%28%23glow%29%22%2F%3E%3Cg%20transform%3D%22rotate%28-32%20450%20350%29%22%3E%3Cellipse%20cx%3D%22450%22%20cy%3D%22350%22%20rx%3D%22238%22%20ry%3D%22140%22%20fill%3D%22none%22%20stroke%3D%22url%28%23ring%29%22%20stroke-width%3D%2258%22%2F%3E%3Ccircle%20cx%3D%22450%22%20cy%3D%22350%22%20r%3D%2291%22%20fill%3D%22url%28%23ball%29%22%2F%3E%3Cpath%20d%3D%22M216%20350c0%2078%20104%20141%20234%20141s234-63%20234-141%22%20fill%3D%22none%22%20stroke%3D%22url%28%23ring%29%22%20stroke-width%3D%2258%22%2F%3E%3Cpath%20d%3D%22M218%20363c20%2075%20140%20128%20260%20119%22%20fill%3D%22none%22%20stroke%3D%22%23e5eaff%22%20stroke-width%3D%223%22%20opacity%3D%22.6%22%2F%3E%3C%2Fg%3E%3Cg%20fill%3D%22%23d0dcff%22%20font-family%3D%22Arial%2Csans-serif%22%3E%3Ctext%20x%3D%2248%22%20y%3D%2266%22%20font-size%3D%2215%22%20letter-spacing%3D%225%22%3EORBIT%20%2F%20MOTION%20STUDY%3C%2Ftext%3E%3Ctext%20x%3D%2248%22%20y%3D%22650%22%20font-size%3D%2217%22%20letter-spacing%3D%222%22%3EA%20DIFFERENT%20PERSPECTIVE.%3C%2Ftext%3E%3Ctext%20x%3D%22804%22%20y%3D%22650%22%20font-size%3D%2217%22%3E03%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fsvg%3E")}.ww-fx-host[data-effect-type="justified-gallery"] .fx{background:#ebe7dc;color:#2a2c23}.ww-fx-host[data-effect-type="justified-gallery"] .fx small,.ww-fx-host[data-effect-type="justified-gallery"] .hint{color:#60674f}.ww-fx-host[data-effect-type="justified-gallery"] .justified{display:flex;gap:10px;align-items:stretch;min-width:0}.ww-fx-host[data-effect-type="justified-gallery"] .justified>button{flex:var(--ratio) 1 0;min-width:0;padding:0;border:0;border-radius:0;position:relative;overflow:hidden;background:transparent}.ww-fx-host[data-effect-type="justified-gallery"] .justified .art{display:block;height:300px;min-height:0;transition:transform .6s cubic-bezier(.2,.8,.2,1)}.ww-fx-host[data-effect-type="justified-gallery"] .justified>button>span:last-child{position:absolute;bottom:13px;left:10px;background:#f1ede3e6;padding:6px 8px;font-size:9px;color:#282d22}.ww-fx-host[data-effect-type="justified-gallery"] .fx[data-playing=true] .justified>button:hover .art,.ww-fx-host[data-effect-type="justified-gallery"] .fx[data-playing=true] .justified>button:focus-visible .art{transform:scale(1.07)}.ww-fx-host[data-effect-type="justified-gallery"] dialog{width:calc(100% - 28px);max-width:720px;border:0;background:#ebe7dc;color:#2a2c23;padding:18px;border-radius:4px}.ww-fx-host[data-effect-type="justified-gallery"] dialog::backdrop{background:#080c11db}.ww-fx-host[data-effect-type="justified-gallery"] dialog .art{height:min(52vh,360px);margin:15px 0;min-height:200px}.ww-fx-host[data-effect-type="justified-gallery"] dialog p{font-size:12px}.ww-fx-host[data-effect-type="justified-gallery"] dialog button{border-color:#777b68}@media(max-width:500px){.ww-fx-host[data-effect-type="justified-gallery"] .justified{gap:7px}.ww-fx-host[data-effect-type="justified-gallery"] .justified .art{height:280px}.ww-fx-host[data-effect-type="justified-gallery"] .justified>button>span:last-child{font-size:7px;left:5px;padding:5px}}
.ww-fx-host{display:block;position:relative;isolation:isolate;max-width:100%;background:#111211;color:#f4f0e7}.ww-fx-host>.ww-fx-controls{display:flex;gap:15px;align-items:center;padding:12px 20px;font:12px Arial,sans-serif}.ww-fx-host .ww-fx-controls button{color:inherit;border:1px solid #ffffff55;background:transparent;border-radius:99px;min-height:42px;padding:8px 18px;cursor:pointer}.ww-fx-host .ww-fx-image{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block}.ww-fx-host .cursor-target{display:block;color:inherit;text-decoration:none}.ww-fx-host .fx{min-height:500px}.ww-fx-host .fx .art{position:relative}.ww-fx-host .fx .portal-art,.ww-fx-host .fx .thumb-destination,.ww-fx-host .fx .scene-art{position:absolute}
{% endstylesheet %}
{% schema %}
{
"name": "WW justified-gallery",
"settings": [
{
"type": "image_picker",
"id": "image_1",
"label": "Image 1"
},
{
"type": "image_picker",
"id": "image_2",
"label": "Image 2"
},
{
"type": "image_picker",
"id": "image_3",
"label": "Image 3"
}
],
"presets": [
{
"name": "WW justified-gallery"
}
]
}
{% endschema %}
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
WESWOO 案例站参考Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license从最后一张缩略图键盘打开放大、关闭,再继续 Tab。若下次渲染移除了原缩略图,就给逻辑上相邻的焦点目标;关掉遮罩本身不会解决焦点丢失。
四组条件都能打开、退出并返回放大按钮。缩放动效是否开启并不决定焦点能否正常归还。
复现实验与读数
从放大按钮打开和关闭弹窗。三个值依次表示打开后是否开启、关闭后是否开启、焦点是否回到放大按钮。
- 908、316 px,两种偏好
- 是,再到 否,再到 是
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 打开大图,再按关闭 | 打开后,弹窗可访问名称为“Enlarged website project screen”。按关闭后,弹窗退出。 |
| 1440 / 908 px | 打开大图,再按关闭 | 打开后,弹窗可访问名称为“Enlarged website project screen”。按关闭后,弹窗退出。 |
正在准备预览
特效说明
先给读者一个具体的查看理由
以背包页面为例,整体图说明外形,拉链和肩带细节帮助读者判断结构。查看入口应说明会打开什么,例如“查看肩带连接处”,而不是让每张图都无差别地放大。先保留可访问的高清图链接,再用弹层增强查看过程,脚本失败也有继续看图的路径。
大图要跟着当前选择走
示例展示单张细节弹层,不等于已经接好真实商品媒体。主题接入应从同一媒体记录取得图片、说明和高清地址,按需请求大图。用户快速换角度或切换变体时,以最后一次选择为准,避免旧请求回来后覆盖新图;加载失败时保留关闭、重试或原图入口。
看完之后继续原来的阅读
原生dialog用于承载查看区域,预览中的弹层只作用在其隔离画布内。真实页面还要安排明确名称、可见关闭入口和合理焦点返回,让Esc退出后回到本次缩略图。手机上的高图不能把关闭按钮挤出屏幕;减少动态时可省去缩放过渡,查看与退出仍完整保留。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="zoom-dialog"><small>14 / TAKE A CLOSER LOOK</small><button type="button" class="zoom-open" aria-haspopup="dialog" aria-label="Enlarge the website project screen"><span class="art" aria-hidden="true"></span><span>Explore the detail +</span></button><dialog aria-label="Enlarged website project screen"><button type="button" data-close>Close ×</button><div class="art" role="img" aria-label="Enlarged SHOKZ website project screen"></div><p>SHOKZ website project screen, shown here to demonstrate image enlargement.</p></dialog></section>
*{box-sizing:border-box}body{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}button,input{font:inherit}button{cursor:pointer;border:1px solid #ffffff50;border-radius:99px;padding:11px 18px;color:inherit;background:transparent;min-height:42px}button:hover{background:#ffffff15}button:focus-visible,a:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.fx{position:relative;min-height:500px;padding:34px;overflow:hidden;display:grid;align-content:center;gap:20px;isolation:isolate;background:#111211}.fx h2,.fx h3,.fx p{margin:0}.fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.fx>small{position:relative;z-index:2;align-self:start}.fx p{max-width:46ch}.fx:after{content:'WESWOO / INTERACTION STUDY';position:absolute;bottom:12px;right:23px;font-size:8px;letter-spacing:.18em;color:inherit;opacity:.45;pointer-events:none}.art{position:relative;min-height:240px;border-radius:3px;overflow:hidden;background-color:#ea754e;background-size:cover;background-position:center}.art:before,.art:after{content:none!important}.hint{font-size:11px;color:#b5b8ad}.controls{display:flex;gap:8px;flex-wrap:wrap}.scroller{height:385px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#b7b9a6 #292a26;border-radius:3px;position:relative;outline-offset:2px;overscroll-behavior-y:contain}.spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.fx [hidden]{display:none!important}.fx[data-playing=false] *{animation-play-state:paused!important}.fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.fx a{color:inherit;text-underline-offset:4px}.fx[data-reduced-motion=true] *,.fx[data-reduced-motion=true] *:before,.fx[data-reduced-motion=true] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
@media(max-width:500px){.fx{padding:22px;min-height:460px;gap:18px}.fx h2{font-size:43px}.fx>small{font-size:8px}.art{min-height:215px}.scroller{height:355px}.fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
.zoom-open{padding:0;border:0;border-radius:12px;text-align:left;width:100%}.zoom-open>.art{display:block;min-height:220px}.zoom-open>span:last-child{display:block;padding:12px}dialog{width:calc(100% - 30px);max-width:680px;border:0;border-radius:14px;background:#16392d;color:#eef5e6;padding:20px}dialog::backdrop{background:#000b}dialog .art{margin:15px 0;min-height:230px}dialog p{font-size:12px}dialog[open] .art{animation:detail-in .35s ease-out}@keyframes detail-in{from{transform:scale(.95);opacity:.4}to{transform:none;opacity:1}}
.fx[data-effect=zoom-dialog]{background:#d6cbb7;color:#373126}.fx[data-effect=zoom-dialog] small{color:#5c5549}.fx[data-effect=zoom-dialog] .zoom-open{color:#29271e;background:transparent}.fx[data-effect=zoom-dialog] .zoom-open>.art{height:340px}.fx[data-effect=zoom-dialog] dialog{background:#eee9de;color:#2d3025;border-radius:4px}.fx[data-effect=zoom-dialog] dialog .art{min-height:290px}.fx[data-reduced-motion=true] .stack-card{position:relative;top:0!important}.fx[data-reduced-motion=true] .horizontal-story{height:370px}.fx[data-reduced-motion=true] .horizontal-pin{overflow-x:auto}.fx[data-reduced-motion=true] .horizontal-track{transform:none!important}.fx[data-reduced-motion=true] .story-grid{grid-template-columns:1fr}.fx[data-reduced-motion=true] .story-image{position:static}.fx[data-reduced-motion=true] .loop-window{overflow-x:auto}.fx[data-reduced-motion=true] .loop-set[aria-hidden=true]{display:none}
/* Real website project imagery; rights remain with the project owners. */
.art{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="1"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="2"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp");background-size:cover;background-position:center} .art[data-art="3"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp");background-size:cover;background-position:center} .art:before,.art:after{content:none!important}// WESWOO original educational example; no third-party runtime required.
export function mountEffect(root, {reducedMotion=false}={}) {
const reduced=reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches;
root.dataset.reducedMotion=String(reduced);
const life=new AbortController(), animations=[];
let active=false, started=false;
const on=(node,type,fn,options={})=>node.addEventListener(type,fn,{...options,signal:life.signal});
const animate=(node,frames,options)=>{
if(reduced)return null;
const animation=node.animate(frames,options);animations.push(animation);return animation;
};
let start=()=>{}, stop=()=>{}, cleanup=()=>{};
const dialog=root.querySelector('dialog'),open=root.querySelector('.zoom-open');
on(open,'click',()=>{if(active&&!dialog.open)dialog.showModal();});on(root.querySelector('[data-close]'),'click',()=>dialog.close());
on(dialog,'click',event=>{if(event.target===dialog){const r=dialog.getBoundingClientRect();if(event.clientX<r.left||event.clientX>r.right||event.clientY<r.top||event.clientY>r.bottom)dialog.close();}});
stop=()=>{if(dialog.open)dialog.close();};cleanup=stop;
root.dataset.playing='false';
return {
resume(){active=true;root.dataset.playing='true';if(!started){started=true;start();}animations.forEach(a=>a.play());root.dispatchEvent(new Event('ww:resume'));},
pause(){active=false;root.dataset.playing='false';animations.forEach(a=>a.pause());stop();},
destroy(){active=false;life.abort();animations.forEach(a=>a.cancel());cleanup();}
};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 商品媒体或工艺 Section;连接真实高分辨率图像,保留当前商品和变体上下文。
交互逻辑
- 点击按钮后打开原生 dialog,使用局部缩放入场;关闭按钮、Escape 和遮罩关闭后恢复触发器焦点。大图可在点击后再加载。
触摸与无障碍
- 减少动态效果不做缩放;手机弹层限制为视口宽高并允许滚动。示例为单图放大,不宣称具备触摸捏合缩放。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
WESWOO 案例站参考Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license快速点两张缩略图再退出,检查显示的是最后一次选择、返回的也是正确缩略图。较早图片晚加载时尤其容易暴露小图和大图不同步。
经过放大过渡后,关闭仍把焦点交还给原缩略图。若替换素材或过渡时间,可重做最后一步查焦点丢失。
复现实验与读数
从第一张缩略图打开原图预览,等待转换完成后关闭。依次读弹窗开、关后的状态及焦点是否回到原图。
- 908、316 px,两种偏好
- 是,再到 否,再到 是
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
正在准备预览
特效说明
过渡连接的是同一张图片
在多图案例中,读者点击局部照片后,图片从原位置展开,可以帮助他把大图与目录位置对应起来。这个过程应服务查看内容,原图链接仍保留,关闭也回到原入口。它不等同于商品变体切换,视频与三维媒体也不能直接套用图像过渡。
位置要在打开和关闭时重新测量
示例测量缩略图和目标图的位置,用位移与缩放连接两者;关闭时读取新的几何位置,适应期间发生的滚动。接入主题可从商品媒体中选图,但要明确数量范围。快速连点、尚未打开就关闭或区域被移除时,旧的异步结果应作废并立即结束,避免迟到的大图再次出现。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="thumbnail-transition"><header class="ww-study-intro"><small>24 / FROM THUMBNAIL TO STORY</small><h2>OPEN A<br><em>NEW WORLD.</em></h2><p>Real website project screens. Open a screen to inspect it, then return to the same position.</p></header><ww-product-flip data-teaching-paused data-state="closed"><div class="ww-thumbs"><a href="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" data-media-id="study-1" aria-haspopup="dialog"><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" alt="SHOKZ website project screen" width="900" height="700"><span class="ww-study-label"><span>SHOKZ</span><span>01 +</span></span></a><a href="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" data-media-id="study-2" aria-haspopup="dialog"><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" alt="TERMINO website project screen" width="900" height="700"><span class="ww-study-label"><span>TERMINO</span><span>02 +</span></span></a><a href="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" data-media-id="study-3" aria-haspopup="dialog"><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" alt="INIU website project screen" width="900" height="700"><span class="ww-study-label"><span>INIU</span><span>03 +</span></span></a></div><div class="ww-dots" aria-label="Gallery pagination"><button type="button" data-slide="0" aria-label="Study 1" aria-pressed="true">●</button><button type="button" data-slide="1" aria-label="Study 2" aria-pressed="false">●</button><button type="button" data-slide="2" aria-label="Study 3" aria-pressed="false">●</button></div><p data-error hidden>Image unavailable. Follow the original image link.</p><dialog aria-label="Expanded website project screen"><div class="ww-tools"><a data-original>Open original image</a><button data-close autofocus>Close ×</button></div><img data-expanded width="900" height="700" alt=""><p data-caption></p></dialog></ww-product-flip></section>ww-product-flip{display:block;color:inherit}ww-product-flip .ww-thumbs{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}ww-product-flip a{color:inherit}ww-product-flip .ww-thumbs img{display:block;width:100%;height:auto}ww-product-flip dialog{border:0;padding:18px;background:#f4f0e7;color:#20241f;width:min(92vw,1000px);max-height:90dvh;overflow:auto}ww-product-flip dialog::backdrop{background:#101210dd}ww-product-flip [data-expanded]{display:block;width:auto;max-width:100%;max-height:65dvh;height:auto;object-fit:contain;transform-origin:0 0}ww-product-flip button{min-width:44px;min-height:44px}ww-product-flip :focus-visible{outline:3px solid #335c2d;outline-offset:4px}ww-product-flip .ww-tools{display:flex;gap:16px;align-items:center;justify-content:space-between}ww-product-flip[data-state="opening"] [data-caption],ww-product-flip[data-state="closing"] [data-caption]{visibility:hidden}@media(max-width:1180px){ww-product-flip .ww-thumbs{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:none}ww-product-flip .ww-thumbs::-webkit-scrollbar{display:none}ww-product-flip .ww-thumbs>a{flex:0 0 85%;max-width:580px;scroll-snap-align:start}ww-product-flip [data-expanded]{height:auto}}
ww-product-flip .ww-dots{display:none}@media(max-width:1180px){ww-product-flip .ww-dots{display:flex;justify-content:center;gap:4px;flex-wrap:wrap}ww-product-flip .ww-dots button{border:0;background:none;font-size:12px;opacity:.45}ww-product-flip .ww-dots [aria-pressed="true"]{opacity:1}}
ww-product-flip .ww-thumbs{position:relative}ww-product-flip .ww-thumbs>a{text-decoration:none}ww-product-flip .ww-study-label{display:flex;justify-content:space-between;padding:14px 0;font-size:12px;letter-spacing:.12em}ww-product-flip .ww-thumbs>a:hover img{filter:brightness(1.04)}ww-product-flip [data-expanded]{margin:12px auto}
html,body{margin:0;background:#ebe6da;color:#22291f;font:14px/1.6 Arial,sans-serif}*{box-sizing:border-box}.fx{padding:28px;background:#ebe6da;color:#22291f;min-height:100vh}.ww-study-intro{display:grid;grid-template-columns:1fr 1fr;gap:12px 28px;align-items:end;margin-bottom:24px}.ww-study-intro small{grid-column:1/-1;letter-spacing:.15em;font-size:10px}.ww-study-intro h2{font:600 clamp(42px,6vw,60px)/.95 Arial;margin:0;letter-spacing:-.05em}.ww-study-intro h2 em{font-family:Georgia,serif;font-weight:400}.ww-study-intro p{max-width:36ch;font:12px/1.7 Arial;margin:0}.ww-study-label{font-family:Arial,sans-serif}button{font:inherit;cursor:pointer}a{color:inherit}@media(max-width:600px){.fx{padding:18px}.ww-study-intro{display:block;margin-bottom:20px}.ww-study-intro h2{font-size:40px;margin:12px 0}.ww-study-intro p{font-size:11px;max-width:38ch}.ww-study-label{font-size:10px!important;padding:10px 0!important}}
// WESWOO original. No third-party dependency. MIT (see LICENSE).
let instanceCount=0;
class WWProductFlip extends HTMLElement {
connectedCallback(){
if(this.life)return; this.life=new AbortController();this.motion=matchMedia('(prefers-reduced-motion: reduce)');
this.dialog=this.querySelector('dialog');this.image=this.querySelector('[data-expanded]');this.state='closed';this.generation=(this.generation||0)+1;this.active=!this.hasAttribute('data-teaching-paused');const caption=this.querySelector('[data-caption]'),strip=this.querySelector('.ww-thumbs');
if(!this.dialog||typeof this.dialog.showModal!=='function'||!this.image||!caption||!strip){this.life.abort();this.life=null;return;}
caption.id='ww-flip-caption-'+(++instanceCount);this.dialog.setAttribute('aria-labelledby',caption.id);
const on=(n,t,f)=>n.addEventListener(t,f,{signal:this.life.signal});
on(this,'click',e=>{if(!this.active){if(e.target.closest('[data-media-id],[data-slide],[data-close]'))e.preventDefault();return;}const dot=e.target.closest('[data-slide]');if(dot){const target=this.querySelectorAll('[data-media-id]')[Number(dot.dataset.slide)];if(!target)return;const strip=this.querySelector('.ww-thumbs'),left=strip.scrollLeft+target.getBoundingClientRect().left-strip.getBoundingClientRect().left;strip.scrollTo({left:Math.max(0,Math.min(strip.scrollWidth-strip.clientWidth,left)),behavior:this.reduced?'auto':'smooth'});return;}const a=e.target.closest('[data-media-id]');if(a&&this.contains(a)&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey&&!e.altKey){e.preventDefault();this.open(a);}if(e.target.closest('[data-close]'))this.close();});
on(this.dialog,'cancel',e=>{e.preventDefault();this.close();});
on(this.dialog,'close',()=>{if(!this.dialog.open)this.reset();});
on(this.image,'error',()=>{this.querySelector('[data-error]').hidden=false;this.close(true);});
on(this.dialog,'click',e=>{if(e.target===this.dialog){const r=this.dialog.getBoundingClientRect();if(e.clientX<r.left||e.clientX>r.right||e.clientY<r.top||e.clientY>r.bottom)this.close();}});
on(window,'resize',()=>{if(this.state!=='closed')this.close(true);this.syncDots();});
on(this.motion,'change',()=>{if(this.state!=='closed')this.close(true);});on(this.querySelector('.ww-thumbs'),'scroll',()=>this.syncDots());this.syncDots();
}
get reduced(){return this.forceReduced||this.motion.matches;}
setActive(value){this.active=value;if(!value)this.close(true);}
syncDots(){const left=this.querySelector('.ww-thumbs').getBoundingClientRect().left;let best=Infinity,index=0;this.querySelectorAll('[data-media-id]').forEach((item,i)=>{const d=Math.abs(item.getBoundingClientRect().left-left);if(d<best){best=d;index=i;}});this.querySelectorAll('[data-slide]').forEach((dot,i)=>dot.setAttribute('aria-pressed',String(index===i)));}
flip(from,to,reverse=false){
if(this.reduced||!this.image.animate||!from?.width||!to.width)return null;
const small={transform:`translate(${from.left-to.left}px,${from.top-to.top}px) scale(${from.width/to.width},${from.height/to.height})`};
const large={transform:'translate(0,0) scale(1,1)'};
return this.image.animate(reverse?[large,small]:[small,large],{duration:520,easing:'cubic-bezier(.2,.8,.2,1)',fill:'both'});
}
async open(a){
if(!this.active||this.state!=='closed')return;const token=++this.generation;this.origin=a;this.querySelector('[data-error]').hidden=true;this.state='opening';this.dataset.state=this.state;
const thumb=a.querySelector('img');this.image.width=thumb.naturalWidth||thumb.width||1200;this.image.height=thumb.naturalHeight||thumb.height||900;this.image.src=a.href;this.image.alt=thumb.alt;
this.querySelector('[data-original]').href=a.href;this.querySelector('[data-caption]').textContent=a.querySelector('img').alt;
try{this.dialog.showModal();}catch{this.reset();location.assign(a.href);return;}
const from=a.querySelector('img').getBoundingClientRect(),to=this.image.getBoundingClientRect();
this.anim=this.flip(from,to);const current=this.anim;
try{await current?.finished;}catch{}if(token!==this.generation||this.state!=='opening')return;
current?.cancel();this.anim=null;this.state='open';this.dataset.state=this.state;
}
async close(immediate=false){
if(this.state==='closed'||(this.state==='closing'&&!immediate))return;const token=++this.generation;
const wasOpening=this.state==='opening';this.state='closing';this.dataset.state=this.state;this.anim?.cancel();
const from=this.origin?.querySelector('img')?.getBoundingClientRect(),to=this.image.getBoundingClientRect();
// Interrupted opening closes immediately, avoiding a geometry jump.
this.anim=!immediate&&!wasOpening&&this.origin?.isConnected?this.flip(from,to,true):null;
if(immediate||wasOpening){if(this.dialog.open)this.dialog.close();this.reset();return;}const current=this.anim;try{await current?.finished;}catch{}if(token!==this.generation||this.state!=='closing')return;
this.anim?.cancel();this.anim=null;this.dialog.close();this.reset();
}
reset(){++this.generation;this.anim?.cancel();this.anim=null;this.state='closed';this.dataset.state=this.state;if(this.origin?.isConnected)this.origin.focus({preventScroll:true});}
disconnectedCallback(){++this.generation;this.life?.abort();this.life=null;this.anim?.cancel();if(this.dialog?.open)this.dialog.close();this.state='closed';}
}
if(!customElements.get('ww-product-flip'))customElements.define('ww-product-flip',WWProductFlip);
export function mountEffect(root,{reducedMotion=false}={}){const el=root.querySelector('ww-product-flip');el.connectedCallback();el.forceReduced=reducedMotion;el.setActive(false);return {resume(){el.setActive(true);root.dataset.playing='true';},pause(){el.setActive(false);root.dataset.playing='false';},destroy(){el.disconnectedCallback();}};}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 复制主题中的独立产品图库 Section,读取
product.media的图片;可选择商品或使用当前商品,最多显示 image_limit 张。保留原图链接,不接管变体、购物车、视频或3D媒体。
交互逻辑
- 打开前测量缩略图,原生 dialog 打开后测量大图,以平移和缩放完成 FLIP。正常关闭反向测量回到缩略图;generation 标记拒绝过期异步完成,暂停、卸载或中断打开立即取消动画并关闭。
触摸与无障碍
- 减少动态直接显示终态;Escape 和关闭按钮均返回焦点。无 JS、缺少 dialog 支持或接入节点不全时保留原图链接;图片加载失败关闭并提示,下一次打开清除旧错误。
本效果的接入说明
文件:复制下方 sections/ww-product-flip.liquid、assets/ww-product-flip.js 与 assets/ww-product-flip.css;Section 自行加载这两个资源,不依赖旧的 ww-effect-studio.js。
数据:使用当前商品或选择商品的 product.media 图片;image_limit 控制最多显示数量。视频与3D不进入此图库;图片为空则显示可编辑的空态说明。
接入:在复制主题添加 Section,编辑标题、关闭/原图/错误/分页等文案并提供适当图片 alt。两次添加须保持独立对话框、焦点与事件清理。
验收:已做本地 Liquid 渲染和 Theme Check;这不等于已安装到商家主题。仍需在真实主题检查图片、样式、键盘和触摸,原生商品媒体与购物车另行核对。
上线检查
接入文件
ww-product-flip{display:block;color:inherit}ww-product-flip .ww-thumbs{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}ww-product-flip a{color:inherit}ww-product-flip .ww-thumbs img{display:block;width:100%;height:auto}ww-product-flip dialog{border:0;padding:18px;background:#f4f0e7;color:#20241f;width:min(92vw,1000px);max-height:90dvh;overflow:auto}ww-product-flip dialog::backdrop{background:#101210dd}ww-product-flip [data-expanded]{display:block;width:auto;max-width:100%;max-height:65dvh;height:auto;object-fit:contain;transform-origin:0 0}ww-product-flip button{min-width:44px;min-height:44px}ww-product-flip :focus-visible{outline:3px solid #335c2d;outline-offset:4px}ww-product-flip .ww-tools{display:flex;gap:16px;align-items:center;justify-content:space-between}ww-product-flip[data-state="opening"] [data-caption],ww-product-flip[data-state="closing"] [data-caption]{visibility:hidden}@media(max-width:1180px){ww-product-flip .ww-thumbs{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:none}ww-product-flip .ww-thumbs::-webkit-scrollbar{display:none}ww-product-flip .ww-thumbs>a{flex:0 0 85%;max-width:580px;scroll-snap-align:start}ww-product-flip [data-expanded]{height:auto}}
ww-product-flip .ww-dots{display:none}@media(max-width:1180px){ww-product-flip .ww-dots{display:flex;justify-content:center;gap:4px;flex-wrap:wrap}ww-product-flip .ww-dots button{border:0;background:none;font-size:12px;opacity:.45}ww-product-flip .ww-dots [aria-pressed="true"]{opacity:1}}
ww-product-flip .ww-thumbs{position:relative}ww-product-flip .ww-thumbs>a{text-decoration:none}ww-product-flip .ww-study-label{display:flex;justify-content:space-between;padding:14px 0;font-size:12px;letter-spacing:.12em}ww-product-flip .ww-thumbs>a:hover img{filter:brightness(1.04)}ww-product-flip [data-expanded]{margin:12px auto}// WESWOO original. No third-party dependency. MIT (see LICENSE).
let instanceCount=0;
export class WWProductFlip extends HTMLElement {
connectedCallback(){
if(this.life)return; this.life=new AbortController();this.motion=matchMedia('(prefers-reduced-motion: reduce)');
this.dialog=this.querySelector('dialog');this.image=this.querySelector('[data-expanded]');this.state='closed';this.generation=(this.generation||0)+1;this.active=!this.hasAttribute('data-teaching-paused');const caption=this.querySelector('[data-caption]'),strip=this.querySelector('.ww-thumbs');
if(!this.dialog||typeof this.dialog.showModal!=='function'||!this.image||!caption||!strip){this.life.abort();this.life=null;return;}
caption.id='ww-flip-caption-'+(++instanceCount);this.dialog.setAttribute('aria-labelledby',caption.id);
const on=(n,t,f)=>n.addEventListener(t,f,{signal:this.life.signal});
on(this,'click',e=>{if(!this.active){if(e.target.closest('[data-media-id],[data-slide],[data-close]'))e.preventDefault();return;}const dot=e.target.closest('[data-slide]');if(dot){const target=this.querySelectorAll('[data-media-id]')[Number(dot.dataset.slide)];if(!target)return;const strip=this.querySelector('.ww-thumbs'),left=strip.scrollLeft+target.getBoundingClientRect().left-strip.getBoundingClientRect().left;strip.scrollTo({left:Math.max(0,Math.min(strip.scrollWidth-strip.clientWidth,left)),behavior:this.reduced?'auto':'smooth'});return;}const a=e.target.closest('[data-media-id]');if(a&&this.contains(a)&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey&&!e.altKey){e.preventDefault();this.open(a);}if(e.target.closest('[data-close]'))this.close();});
on(this.dialog,'cancel',e=>{e.preventDefault();this.close();});
on(this.dialog,'close',()=>{if(!this.dialog.open)this.reset();});
on(this.image,'error',()=>{this.querySelector('[data-error]').hidden=false;this.close(true);});
on(this.dialog,'click',e=>{if(e.target===this.dialog){const r=this.dialog.getBoundingClientRect();if(e.clientX<r.left||e.clientX>r.right||e.clientY<r.top||e.clientY>r.bottom)this.close();}});
on(window,'resize',()=>{if(this.state!=='closed')this.close(true);this.syncDots();});
on(this.motion,'change',()=>{if(this.state!=='closed')this.close(true);});on(this.querySelector('.ww-thumbs'),'scroll',()=>this.syncDots());this.syncDots();
}
get reduced(){return this.forceReduced||this.motion.matches;}
setActive(value){this.active=value;if(!value)this.close(true);}
syncDots(){const left=this.querySelector('.ww-thumbs').getBoundingClientRect().left;let best=Infinity,index=0;this.querySelectorAll('[data-media-id]').forEach((item,i)=>{const d=Math.abs(item.getBoundingClientRect().left-left);if(d<best){best=d;index=i;}});this.querySelectorAll('[data-slide]').forEach((dot,i)=>dot.setAttribute('aria-pressed',String(index===i)));}
flip(from,to,reverse=false){
if(this.reduced||!this.image.animate||!from?.width||!to.width)return null;
const small={transform:`translate(${from.left-to.left}px,${from.top-to.top}px) scale(${from.width/to.width},${from.height/to.height})`};
const large={transform:'translate(0,0) scale(1,1)'};
return this.image.animate(reverse?[large,small]:[small,large],{duration:520,easing:'cubic-bezier(.2,.8,.2,1)',fill:'both'});
}
async open(a){
if(!this.active||this.state!=='closed')return;const token=++this.generation;this.origin=a;this.querySelector('[data-error]').hidden=true;this.state='opening';this.dataset.state=this.state;
const thumb=a.querySelector('img');this.image.width=thumb.naturalWidth||thumb.width||1200;this.image.height=thumb.naturalHeight||thumb.height||900;this.image.src=a.href;this.image.alt=thumb.alt;
this.querySelector('[data-original]').href=a.href;this.querySelector('[data-caption]').textContent=a.querySelector('img').alt;
try{this.dialog.showModal();}catch{this.reset();location.assign(a.href);return;}
const from=a.querySelector('img').getBoundingClientRect(),to=this.image.getBoundingClientRect();
this.anim=this.flip(from,to);const current=this.anim;
try{await current?.finished;}catch{}if(token!==this.generation||this.state!=='opening')return;
current?.cancel();this.anim=null;this.state='open';this.dataset.state=this.state;
}
async close(immediate=false){
if(this.state==='closed'||(this.state==='closing'&&!immediate))return;const token=++this.generation;
const wasOpening=this.state==='opening';this.state='closing';this.dataset.state=this.state;this.anim?.cancel();
const from=this.origin?.querySelector('img')?.getBoundingClientRect(),to=this.image.getBoundingClientRect();
// Interrupted opening closes immediately, avoiding a geometry jump.
this.anim=!immediate&&!wasOpening&&this.origin?.isConnected?this.flip(from,to,true):null;
if(immediate||wasOpening){if(this.dialog.open)this.dialog.close();this.reset();return;}const current=this.anim;try{await current?.finished;}catch{}if(token!==this.generation||this.state!=='closing')return;
this.anim?.cancel();this.anim=null;this.dialog.close();this.reset();
}
reset(){++this.generation;this.anim?.cancel();this.anim=null;this.state='closed';this.dataset.state=this.state;if(this.origin?.isConnected)this.origin.focus({preventScroll:true});}
disconnectedCallback(){++this.generation;this.life?.abort();this.life=null;this.anim?.cancel();if(this.dialog?.open)this.dialog.close();this.state='closed';}
}
if(!customElements.get('ww-product-flip'))customElements.define('ww-product-flip',WWProductFlip);
{{ 'ww-product-flip.css' | asset_url | stylesheet_tag }}
<script src="{{ 'ww-product-flip.js' | asset_url }}" type="module"></script>
{% assign gallery_product = section.settings.product | default: product %}
{% assign gallery_images = gallery_product.media | where: 'media_type', 'image' | slice: 0, section.settings.image_limit %}
{% if gallery_product != blank and gallery_images.size > 0 %}
<ww-product-flip id="WWFlip-{{ section.id }}" data-state="closed">
<h2 id="WWFlipTitle-{{ section.id }}">{{ section.settings.heading | escape }}</h2>
<div class="ww-thumbs" aria-labelledby="WWFlipTitle-{{ section.id }}">
{% for media in gallery_images %}
{% assign alt = media.alt | default: gallery_product.title %}
<a href="{{ media.preview_image | image_url: width: 2400 | escape }}" data-media-id="{{ media.id }}" aria-haspopup="dialog">
{{ media.preview_image | image_url: width: 960 | image_tag: alt: alt, loading: 'lazy', widths: '320, 640, 960', sizes: '(max-width: 1180px) 85vw, 45vw' }}
</a>
{% endfor %}
</div>
{% if gallery_images.size > 1 %}<div class="ww-dots" aria-label="{{ section.settings.pagination_label | escape }}">{% for media in gallery_images %}<button type="button" data-slide="{{ forloop.index0 }}" aria-label="{{ section.settings.item_label | escape }} {{ forloop.index }}" aria-pressed="{% if forloop.first %}true{% else %}false{% endif %}">●</button>{% endfor %}</div>{% endif %}
<p data-error hidden>{{ section.settings.error_text | escape }}</p>
<dialog aria-labelledby="WWFlipCaption-{{ section.id }}">
<div class="ww-tools"><a data-original>{{ section.settings.original_text | escape }}</a><button type="button" data-close autofocus>{{ section.settings.close_text | escape }}</button></div>
<img data-expanded width="1200" height="900" alt="">
<p id="WWFlipCaption-{{ section.id }}" data-caption></p>
</dialog>
</ww-product-flip>
{% elsif request.design_mode %}<p>Select a product containing image media.</p>{% endif %}
{% schema %}
{
"name": "WW product image FLIP",
"settings": [
{
"type": "product",
"id": "product",
"label": "Product (optional on PDP)"
},
{
"type": "text",
"id": "heading",
"label": "Heading",
"default": "Explore the details"
},
{
"type": "text",
"id": "close_text",
"label": "Close label",
"default": "Close"
},
{
"type": "text",
"id": "original_text",
"label": "Original image label",
"default": "Open original image"
},
{
"type": "text",
"id": "error_text",
"label": "Load error",
"default": "Image unavailable. Use the original image link."
},
{
"type": "range",
"id": "image_limit",
"label": "Maximum images in this Section",
"min": 1,
"max": 12,
"step": 1,
"default": 6
},
{
"type": "text",
"id": "pagination_label",
"label": "Pagination label",
"default": "Gallery pagination"
},
{
"type": "text",
"id": "item_label",
"label": "Image item label",
"default": "View image"
}
],
"presets": [
{
"name": "WW product image FLIP"
}
]
}
{% endschema %}
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
原始视觉选题与官方实现依据原案例只提供缩略图连续转场的视觉方向;本页双向产品图库由 WESWOO 原创实现,演示插图为既有原创设计研究,不是客户案例或商家实装。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license顾客暂停轮播后仍应能手动选图。旧代码暂停时点第三个圆点会停在第一张;新版在暂停状态直接切到第三张。用“能停止运动”和“能主动导航”分别验收。
两个方向都能越过中间一幅。即使图片很像,也可通过状态文字确认圆点是否真的换了页。
复现实验与读数
从第一页直接选第三个圆点,再选第一个,读取两次状态播报。
- 908、316 px,两种偏好
- Slide 3 of 3. No automatic advancement.,再到 Slide 1 of 3. No automatic advancement.
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 选第二个圆点 | 第二个圆点被选中,状态从第 1 张变为第 2 张,共 3 张。 |
| 1440 / 908 px | 选第二个圆点 | 第二个圆点被选中,状态从第 1 张变为第 2 张,共 3 张。 |
正在准备预览
特效说明
几张卡片为什么值得放在一起
例如介绍咖啡器具的准备、研磨和冲煮步骤,读者可能想逐组看图,也可能直接跳到正在做的一步。主动轮播给这些内容一个共同位置,圆点表示还有哪些组可选。商品推荐则先解决哪些商品有资格出现,两者的数据与目的不同,不应因为用了滑动外观就混为一谈。
按钮和手势要说同一件事
示例用原生横向滚动承载卡片,点选按钮定位到对应起点,再从实际滚动位置更新当前状态。这样手指拖动后,圆点也能跟上。接入时让每个按钮有可理解的名称,保留商品的真实链接;激活选择后焦点留在按钮,方便继续比较。
卡片宽度随阅读空间调整
当前预览始终展示滑动轨道。实际网站采用时,手机和平板可保留一张完整卡片与下一张的线索,桌面则按内容选择网格或滑动,并不会由此示例自动切换。屏宽、图片和翻译改变后重新判断首尾位置,避免最后一组只能露出一半。示例没有自动播放;减少动态时直接定位,脚本失败时也应保留可读列表。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="content-slider"><small>15 / CHOOSE YOUR PACE</small><div class="slides" tabindex="0" aria-label="Swipe the three website project screens"><div class="slide"><div class="art" data-art="1"></div><strong>01 / SHOKZ</strong></div><div class="slide"><div class="art" data-art="2"></div><strong>02 / TERMINO</strong></div><div class="slide"><div class="art" data-art="3"></div><strong>03 / INIU</strong></div></div><div class="slide-dots" role="group" aria-label="Choose a slide"><button type="button" data-slide="0" aria-pressed="true" aria-label="Slide 1">1</button><button type="button" data-slide="1" aria-pressed="false" aria-label="Slide 2">2</button><button type="button" data-slide="2" aria-pressed="false" aria-label="Slide 3">3</button></div><p class="hint" role="status">Slide 1 of 3. No automatic advancement.</p></section>
*{box-sizing:border-box}body{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}button,input{font:inherit}button{cursor:pointer;border:1px solid #ffffff50;border-radius:99px;padding:11px 18px;color:inherit;background:transparent;min-height:42px}button:hover{background:#ffffff15}button:focus-visible,a:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.fx{position:relative;min-height:500px;padding:34px;overflow:hidden;display:grid;align-content:center;gap:20px;isolation:isolate;background:#111211}.fx h2,.fx h3,.fx p{margin:0}.fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.fx>small{position:relative;z-index:2;align-self:start}.fx p{max-width:46ch}.fx:after{content:'WESWOO / INTERACTION STUDY';position:absolute;bottom:12px;right:23px;font-size:8px;letter-spacing:.18em;color:inherit;opacity:.45;pointer-events:none}.art{position:relative;min-height:240px;border-radius:3px;overflow:hidden;background-color:#ea754e;background-size:cover;background-position:center}.art:before,.art:after{content:none!important}.hint{font-size:11px;color:#b5b8ad}.controls{display:flex;gap:8px;flex-wrap:wrap}.scroller{height:385px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#b7b9a6 #292a26;border-radius:3px;position:relative;outline-offset:2px;overscroll-behavior-y:contain}.spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.fx [hidden]{display:none!important}.fx[data-playing=false] *{animation-play-state:paused!important}.fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.fx a{color:inherit;text-underline-offset:4px}.fx[data-reduced-motion=true] *,.fx[data-reduced-motion=true] *:before,.fx[data-reduced-motion=true] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
@media(max-width:500px){.fx{padding:22px;min-height:460px;gap:18px}.fx h2{font-size:43px}.fx>small{font-size:8px}.art{min-height:215px}.scroller{height:355px}.fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
.slides{display:flex;gap:14px;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:none}.slides::-webkit-scrollbar{display:none}.slide{flex:0 0 88%;scroll-snap-align:start}.slide .art{min-height:210px}.slide strong{display:block;margin-top:10px}.slide-dots{display:flex;gap:10px;justify-content:center}.slide-dots button{width:36px;height:36px;padding:0;border-radius:50%;font-size:12px}
.fx[data-effect=content-slider] .slide .art{height:330px}.fx[data-effect=content-slider] .slide strong{font:italic 18px Georgia,serif}.fx[data-reduced-motion=true] .stack-card{position:relative;top:0!important}.fx[data-reduced-motion=true] .horizontal-story{height:370px}.fx[data-reduced-motion=true] .horizontal-pin{overflow-x:auto}.fx[data-reduced-motion=true] .horizontal-track{transform:none!important}.fx[data-reduced-motion=true] .story-grid{grid-template-columns:1fr}.fx[data-reduced-motion=true] .story-image{position:static}.fx[data-reduced-motion=true] .loop-window{overflow-x:auto}.fx[data-reduced-motion=true] .loop-set[aria-hidden=true]{display:none}
@media(max-width:600px){.fx[data-effect=content-slider] .slide .art{height:300px}}
/* Real website project imagery; rights remain with the project owners. */
.art{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="1"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="2"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp");background-size:cover;background-position:center} .art[data-art="3"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp");background-size:cover;background-position:center} .art:before,.art:after{content:none!important}// WESWOO original educational example; no third-party runtime required.
export function mountEffect(root, {reducedMotion=false}={}) {
const reduced=reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches;
root.dataset.reducedMotion=String(reduced);
const life=new AbortController(), animations=[];
let active=false, started=false;
const on=(node,type,fn,options={})=>node.addEventListener(type,fn,{...options,signal:life.signal});
const animate=(node,frames,options)=>{
if(reduced)return null;
const animation=node.animate(frames,options);animations.push(animation);return animation;
};
let start=()=>{}, stop=()=>{}, cleanup=()=>{};
const viewport=root.querySelector('.slides'),slides=[...root.querySelectorAll('.slide')],dots=[...root.querySelectorAll('[data-slide]')];
dots.forEach((button,i)=>on(button,'click',()=>{viewport.scrollTo({left:slides[i].offsetLeft-slides[0].offsetLeft,behavior:reduced||!active?'instant':'smooth'});}));
let frame=0;function reflect(){frame=0;let index=0,distance=Infinity;slides.forEach((slide,i)=>{const delta=Math.abs(slide.offsetLeft-slides[0].offsetLeft-viewport.scrollLeft);if(delta<distance){distance=delta;index=i;}});dots.forEach((button,i)=>button.setAttribute('aria-pressed',String(i===index)));root.querySelector('[role=status]').textContent=`Slide ${index+1} of ${slides.length}. No automatic advancement.`;}
on(viewport,'scroll',()=>{if(!frame)frame=requestAnimationFrame(reflect);},{passive:true});cleanup=()=>cancelAnimationFrame(frame);
root.dataset.playing='false';
return {
resume(){active=true;root.dataset.playing='true';if(!started){started=true;start();}animations.forEach(a=>a.play());root.dispatchEvent(new Event('ww:resume'));},
pause(){active=false;root.dataset.playing='false';animations.forEach(a=>a.pause());stop();},
destroy(){active=false;life.abort();animations.forEach(a=>a.cancel());cleanup();}
};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 首页内容、系列介绍或案例 Section;优先整合主题已有轮播,避免同页重复加载轮播库。
交互逻辑
- CSS scroll-snap 提供原生滑动,圆点用 scrollTo 对齐目标起点;滚动时找最接近容器起点的项,更新 aria-pressed 和状态文本。
触摸与无障碍
- 没有自动前进;减少动态效果用即时定位。保留键盘可聚焦滚动区和可点圆点。示例是局部实现,生产中复用现有组件。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
WESWOO 案例站参考Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license从最后一项回到第一项后用键盘逐个访问链接,检查循环复制是否制造重复焦点。装饰轨道可以重复,实际商品入口应可稳定访问,不依赖等到下一圈。
桌面预览和窄预览都只需一条循环。减少动态效果时计数始终为零,图片条仍在文档中。
复现实验与读数
启动循环、暂停、恢复,记录运行中的动画数。
- 908、316 px,默认动态
- 1,再到 0,再到 1
- 908、316 px,减少动态效果
- 0,再到 0,再到 0
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
正在准备预览
特效说明
连续观看不应变成寻找任务
灵感页可以让材质或场景图片不断经过,读者获得整体视觉印象。如果必须追着某一张才能查看商品,循环就会妨碍选择。把作品名、商品链接和必要说明放在稳定列表中,连续图库用来补充情绪,而不是承载唯一的内容入口。
两组图片共同形成接缝
示例将同样的图片组复制一次,移动到总宽度一半时形成循环。两组尺寸和间距要一致,真实素材也须有可使用的权利。重复组不放可聚焦控件,避免键盘进入一份不断移动的副本;暂停后能够从容观看,减少动态时保留一份静态图库即可。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="loop-gallery"><small>16 / A DECORATIVE LOOP</small><h2>KEEP EXPLORING.</h2><div class="loop-window" aria-label="Website project screen strip"><div class="loop-track"><div class="loop-set"><div class="art" data-art="1"></div><div class="art" data-art="2"></div><div class="art" data-art="3"></div></div><div class="loop-set" aria-hidden="true"><div class="art" data-art="1"></div><div class="art" data-art="2"></div><div class="art" data-art="3"></div></div></div></div><p class="hint">A decorative loop. Put real links in a separate, stable list.</p></section>
*{box-sizing:border-box}body{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}button,input{font:inherit}button{cursor:pointer;border:1px solid #ffffff50;border-radius:99px;padding:11px 18px;color:inherit;background:transparent;min-height:42px}button:hover{background:#ffffff15}button:focus-visible,a:focus-visible,input:focus-visible,[tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.fx{position:relative;min-height:500px;padding:34px;overflow:hidden;display:grid;align-content:center;gap:20px;isolation:isolate;background:#111211}.fx h2,.fx h3,.fx p{margin:0}.fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.fx>small{position:relative;z-index:2;align-self:start}.fx p{max-width:46ch}.fx:after{content:'WESWOO / INTERACTION STUDY';position:absolute;bottom:12px;right:23px;font-size:8px;letter-spacing:.18em;color:inherit;opacity:.45;pointer-events:none}.art{position:relative;min-height:240px;border-radius:3px;overflow:hidden;background-color:#ea754e;background-size:cover;background-position:center}.art:before,.art:after{content:none!important}.hint{font-size:11px;color:#b5b8ad}.controls{display:flex;gap:8px;flex-wrap:wrap}.scroller{height:385px;overflow-y:auto;scrollbar-width:thin;scrollbar-color:#b7b9a6 #292a26;border-radius:3px;position:relative;outline-offset:2px;overscroll-behavior-y:contain}.spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.fx [hidden]{display:none!important}.fx[data-playing=false] *{animation-play-state:paused!important}.fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.fx a{color:inherit;text-underline-offset:4px}.fx[data-reduced-motion=true] *,.fx[data-reduced-motion=true] *:before,.fx[data-reduced-motion=true] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}
@media(max-width:500px){.fx{padding:22px;min-height:460px;gap:18px}.fx h2{font-size:43px}.fx>small{font-size:8px}.art{min-height:215px}.scroller{height:355px}.fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}
.loop-window{overflow:hidden;margin:0 -30px}.loop-track{display:flex;width:max-content}.loop-set{display:flex;gap:16px;padding-right:16px;flex:none}.loop-set .art{width:200px;min-height:180px}.loop-set .art:before{left:10%}@media(prefers-reduced-motion:reduce){.loop-window{overflow-x:auto}.loop-set[aria-hidden=true]{display:none}}
.fx[data-effect=loop-gallery]{background:#ddd6c7;color:#282b23}.fx[data-effect=loop-gallery] small,.fx[data-effect=loop-gallery] .hint{color:#626550}.fx[data-effect=loop-gallery] h2{font-size:clamp(36px,6vw,64px)}.fx[data-effect=loop-gallery] .loop-set .art{width:265px;min-height:255px}.fx[data-reduced-motion=true] .stack-card{position:relative;top:0!important}.fx[data-reduced-motion=true] .horizontal-story{height:370px}.fx[data-reduced-motion=true] .horizontal-pin{overflow-x:auto}.fx[data-reduced-motion=true] .horizontal-track{transform:none!important}.fx[data-reduced-motion=true] .story-grid{grid-template-columns:1fr}.fx[data-reduced-motion=true] .story-image{position:static}.fx[data-reduced-motion=true] .loop-window{overflow-x:auto}.fx[data-reduced-motion=true] .loop-set[aria-hidden=true]{display:none}
@media(max-width:600px){.fx[data-effect=loop-gallery] .loop-set .art{width:210px;min-height:230px}}
/* Real website project imagery; rights remain with the project owners. */
.art{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="1"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp");background-size:cover;background-position:center} .art[data-art="2"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp");background-size:cover;background-position:center} .art[data-art="3"]{background-image:url("https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp");background-size:cover;background-position:center} .art:before,.art:after{content:none!important}// WESWOO original educational example; no third-party runtime required.
export function mountEffect(root, {reducedMotion=false}={}) {
const reduced=reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches;
root.dataset.reducedMotion=String(reduced);
const life=new AbortController(), animations=[];
let active=false, started=false;
const on=(node,type,fn,options={})=>node.addEventListener(type,fn,{...options,signal:life.signal});
const animate=(node,frames,options)=>{
if(reduced)return null;
const animation=node.animate(frames,options);animations.push(animation);return animation;
};
let start=()=>{}, stop=()=>{}, cleanup=()=>{};
start=()=>animate(root.querySelector('.loop-track'),[{transform:'translateX(0)'},{transform:'translateX(-50%)'}],{duration:22000,iterations:Infinity,easing:'linear'});
root.dataset.playing='false';
return {
resume(){active=true;root.dataset.playing='true';if(!started){started=true;start();}animations.forEach(a=>a.play());root.dispatchEvent(new Event('ww:resume'));},
pause(){active=false;root.dataset.playing='false';animations.forEach(a=>a.pause());stop();},
destroy(){active=false;life.abort();animations.forEach(a=>a.cancel());cleanup();}
};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 品牌气氛或灵感 Section;使用经授权的轻量素材,重要作品链接放在静止列表中。
交互逻辑
- 两份等宽图组组成轨道,移动半个总宽度循环;复制组 aria-hidden,内部不放可聚焦控件。暂停和页面隐藏停止动画。
触摸与无障碍
- 减少动态效果隐藏重复组,允许直接横向查看原图组;不用它展示必须逐个确认的商品和法律信息。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
WESWOO 案例站参考Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license把分隔线推到两端,再让只有键盘或不能精细拖动的人分别查看左右图。若素材拍摄角度不同,说明比较条件,不能把画面差异说成产品性能差。
控件的两个端点把裁切推到 100% 和 0%。移植时若滑块值变了而裁图没变,可从这个值查两者是否仍连接。
复现实验与读数
从中点把第一组分隔线拉到最大、最小,读取实际用于裁图的百分比。
- 908、316 px,两种偏好
- 50%,再到 100%,再到 0%
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 聚焦第一条分隔线,按 End | 分隔线初始值为 50,按 End 后到达上限 100。 |
| 1440 / 908 px | 聚焦第一条分隔线,按 End | 分隔线初始值为 50,按 End 后到达上限 100。 |
正在准备预览
特效说明
使用说明
用滑块对照不同项目页面截图构图。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class='fx gallery' lang='en'><div class='rail'><article class='card'><div class='cmp' data-cmp><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp' alt='SHOKZ page screenshot'><div class='top'><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp' alt='TERMINO page screenshot'></div><b>TERMINO</b><strong>SHOKZ</strong></div><label>Move divider<input type='range' min='0' max='100' value='50'></label></article><article class='card'><div class='cmp' data-cmp><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp' alt='INIU page screenshot'><div class='top'><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp' alt='FMS page screenshot'></div><b>FMS</b><strong>INIU</strong></div><label>Move divider<input type='range' min='0' max='100' value='50'></label></article><article class='card'><div class='cmp' data-cmp><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp' alt='TERMINO page screenshot'><div class='top'><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp' alt='INIU page screenshot'></div><b>INIU</b><strong>TERMINO</strong></div><label>Move divider<input type='range' min='0' max='100' value='50'></label></article></div><nav class='dots'><button data-dot type='button' aria-label='Screen 1' aria-pressed='true'></button><button data-dot type='button' aria-label='Screen 2' aria-pressed='false'></button><button data-dot type='button' aria-label='Screen 3' aria-pressed='false'></button></nav></section>.gallery.fx{max-width:1100px;margin:auto;padding:24px;background:#f2f0e8;color:#22372e;font:16px/1.6 system-ui,sans-serif}.gallery *{box-sizing:border-box}.rail{display:grid;grid-auto-flow:column;grid-auto-columns:calc(100% - 40px);gap:14px;overflow:auto;scroll-snap-type:x mandatory;scrollbar-width:none;overscroll-behavior-x:contain}.rail::-webkit-scrollbar{display:none}.card{min-width:0;scroll-snap-align:start}.card img{display:block;width:100%;height:100%;object-fit:cover;object-position:top}.dots{display:flex;justify-content:center;gap:12px;margin:14px}.dots button{width:16px;height:16px;border:2px solid #315241;border-radius:50%;background:transparent}.dots [aria-pressed=true]{background:#315241}.gallery :focus-visible{outline:3px solid #a45d13}@media(min-width:760px){.rail{grid-auto-flow:initial;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible}.dots{display:none}}@media(prefers-reduced-motion:reduce){.gallery *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}.cmp{position:relative;aspect-ratio:16/10;overflow:hidden;--cut:50%}.cmp>img{height:100%}.cmp .top{position:absolute;inset:0 auto 0 0;width:var(--cut);overflow:hidden;border-right:2px solid white}.cmp .top img{max-width:none}.cmp b,.cmp strong{position:absolute;top:5px;background:#173629;color:white;padding:4px}.cmp b{left:5px}.cmp strong{right:5px}.card input{width:100%;min-height:44px;touch-action:pan-y}
.g-credit{font-size:12px;letter-spacing:.04em;color:#526157}.g-source{position:absolute;left:8px;bottom:8px;padding:3px 8px;border-radius:12px;background:#183628dd;color:#fff;font-size:11px;z-index:2}
.card input[type=range]{appearance:none;-webkit-appearance:none;background:transparent;cursor:ew-resize}.card input[type=range]::-webkit-slider-runnable-track{height:8px;border-radius:8px;background:linear-gradient(90deg,#24543e,#9aac9e)}.card input[type=range]::-moz-range-track{height:8px;border-radius:8px;background:linear-gradient(90deg,#24543e,#9aac9e)}.card input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;width:24px;height:24px;margin-top:-8px;border:3px solid #f2f0e8;border-radius:50%;background:#24543e;box-shadow:0 0 0 2px #24543e}.card input[type=range]::-moz-range-thumb{width:18px;height:18px;border:3px solid #f2f0e8;border-radius:50%;background:#24543e;box-shadow:0 0 0 2px #24543e}
export function mountEffect(root,{reducedMotion=false}={}){const ctl=new AbortController(),signal=ctl.signal,rail=root.querySelector('.rail'),cards=[...root.querySelectorAll('.card')],dots=[...root.querySelectorAll('[data-dot]')];let paused=false,dead=false;const noMotion=()=>reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches||paused;function go(i){if(dead||!cards[i])return;rail.scrollTo({left:cards[i].offsetLeft-cards[0].offsetLeft,behavior:noMotion()?'instant':'smooth'});dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)));}dots.forEach((d,i)=>d.addEventListener('click',()=>go(i),{signal}));rail.addEventListener('scroll',()=>{const x=rail.scrollLeft+cards[0].offsetLeft,i=cards.reduce((b,c,n)=>Math.abs(c.offsetLeft-x)<Math.abs(cards[b].offsetLeft-x)?n:b,0);dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(i===n)));},{passive:true,signal});root.querySelectorAll('.cmp').forEach(x=>{const r=x.parentElement.querySelector('input'),t=x.querySelector('.top');function u(){x.style.setProperty('--cut',r.value+'%');t.firstElementChild.style.width=x.clientWidth+'px'}r.addEventListener('input',u,{signal});new ResizeObserver(u).observe(x);u()});return{resume(){if(!dead){paused=false;root.dataset.paused='false';}},pause(){paused=true;root.dataset.paused='true';rail.scrollTo({left:rail.scrollLeft,behavior:'instant'});},destroy(){dead=true;ctl.abort();delete root.dataset.paused;}}}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 用于网页审阅;截图不代表产品或客户效果数据。
交互逻辑
- 原生范围控件裁切上层截图。
触摸与无障碍
- 无脚本时保留截图和文字;页面可正常纵向滚动。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
Codrops 交互参考Codrops ScrollBasedLayoutAnimations 仅作布局交互方向参考;本例分隔线由原生 range 独立编写,未复制该仓库代码或引入运行库。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license把同一画面从横框换成窄框,核对热点指向的仍是同一部件,再用文字控件选择它。若图像裁切变了,旧百分比坐标即使可点也可能标错部位。
图上热点和图下文字都能控制同一段说明。手指点不中小热点时,文字入口仍能回到开场说明。
复现实验与读数
读第一幅图的默认说明,按第三个热点,再按第一个文字入口,记录三段可见说明。
- 908、316 px,两种偏好
- Review the page opening.,再到 Look for a next step.,再到 Review the page opening.
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 2 | 选中或展开的控件为“2 / Visual focus / 1 / Opening / 1”。 |
| 1440 / 908 px | 2 | 选中或展开的控件为“2 / Visual focus / 1 / Opening / 1”。 |
正在准备预览
特效说明
使用说明
切换页面观察提示;不标注商品部件。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class='fx gallery' lang='en'><div class='rail'><article class='card'><div class='shot'><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" alt="SHOKZ WESWOO project page screenshot" loading="lazy"><span class="g-source">SHOKZ · WESWOO project page screenshot</span><button type="button" data-p='0' aria-pressed='true' style='--x:70%;--y:20%'>1</button><button type="button" data-p='1' aria-pressed='false' style='--x:50%;--y:50%'>2</button><button type="button" data-p='2' aria-pressed='false' style='--x:75%;--y:80%'>3</button></div><div class='hot-controls'><button type="button" data-s='0' aria-pressed='true'>Opening</button><button type="button" data-s='1' aria-pressed='false'>Visual focus</button><button type="button" data-s='2' aria-pressed='false'>Next step</button></div><p data-n='0' >Review the page opening.</p><p data-n='1' hidden>Notice image and text.</p><p data-n='2' hidden>Look for a next step.</p></article><article class='card'><div class='shot'><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" alt="INIU WESWOO project page screenshot" loading="lazy"><span class="g-source">INIU · WESWOO project page screenshot</span><button type="button" data-p='0' aria-pressed='true' style='--x:70%;--y:20%'>1</button><button type="button" data-p='1' aria-pressed='false' style='--x:50%;--y:50%'>2</button><button type="button" data-p='2' aria-pressed='false' style='--x:75%;--y:80%'>3</button></div><div class='hot-controls'><button type="button" data-s='0' aria-pressed='true'>Opening</button><button type="button" data-s='1' aria-pressed='false'>Visual focus</button><button type="button" data-s='2' aria-pressed='false'>Next step</button></div><p data-n='0' >Review the page opening.</p><p data-n='1' hidden>Notice image and text.</p><p data-n='2' hidden>Look for a next step.</p></article><article class='card'><div class='shot'><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp" alt="FMS WESWOO project page screenshot" loading="lazy"><span class="g-source">FMS · WESWOO project page</span><button type="button" data-p='0' aria-pressed='true' style='--x:70%;--y:20%'>1</button><button type="button" data-p='1' aria-pressed='false' style='--x:50%;--y:50%'>2</button><button type="button" data-p='2' aria-pressed='false' style='--x:75%;--y:80%'>3</button></div><div class='hot-controls'><button type="button" data-s='0' aria-pressed='true'>Opening</button><button type="button" data-s='1' aria-pressed='false'>Visual focus</button><button type="button" data-s='2' aria-pressed='false'>Next step</button></div><p data-n='0' >Review the page opening.</p><p data-n='1' hidden>Notice image and text.</p><p data-n='2' hidden>Look for a next step.</p></article></div><nav class='dots'><button data-dot type='button' aria-label='Screen 1' aria-pressed='true'></button><button data-dot type='button' aria-label='Screen 2' aria-pressed='false'></button><button data-dot type='button' aria-label='Screen 3' aria-pressed='false'></button></nav></section>.gallery.fx{max-width:1100px;margin:auto;padding:24px;background:#f2f0e8;color:#22372e;font:16px/1.6 system-ui,sans-serif}.gallery *{box-sizing:border-box}.rail{display:grid;grid-auto-flow:column;grid-auto-columns:calc(100% - 40px);gap:14px;overflow:auto;scroll-snap-type:x mandatory;scrollbar-width:none;overscroll-behavior-x:contain}.rail::-webkit-scrollbar{display:none}.card{min-width:0;scroll-snap-align:start}.card img{display:block;width:100%;height:100%;object-fit:cover;object-position:top}.dots{display:flex;justify-content:center;gap:12px;margin:14px}.dots button{width:16px;height:16px;border:2px solid #315241;border-radius:50%;background:transparent}.dots [aria-pressed=true]{background:#315241}.gallery :focus-visible{outline:3px solid #a45d13}@media(min-width:760px){.rail{grid-auto-flow:initial;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible}.dots{display:none}}@media(prefers-reduced-motion:reduce){.gallery *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}.shot{position:relative;aspect-ratio:16/10;overflow:hidden}.shot button[data-p]{position:absolute;left:var(--x);top:var(--y);width:44px;height:44px;border-radius:50%;background:#24543e;color:white}.card [data-s]{min-height:44px;margin:4px}.card p{min-height:2em}
.g-credit{font-size:12px;letter-spacing:.04em;color:#526157}.g-source{position:absolute;left:8px;bottom:8px;padding:3px 8px;border-radius:12px;background:#183628dd;color:#fff;font-size:11px;z-index:2}
.shot{background:#f4f4ef}.shot button[data-p]{border:2px solid #fff;background:#24543e;color:#fff;font:700 17px/1 system-ui;box-shadow:0 2px 10px #14261d80;cursor:pointer}.shot button[data-p][aria-pressed=true]{background:#a65019;transform:translate(-50%,-50%) scale(1.08)}.hot-controls{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0}.hot-controls button{flex:1 1 auto;min-width:0;min-height:46px;padding:8px 12px;border:1px solid #476453;border-radius:24px;background:#fff;color:#20372b;font:600 14px/1.35 system-ui;cursor:pointer}.hot-controls button[aria-pressed=true]{background:#24543e;color:white}.hot-controls button:focus-visible,.shot button:focus-visible{outline:3px solid #a45d13;outline-offset:3px}.hot-notes{padding:10px 12px;border-left:3px solid #a65019;background:#fff;border-radius:0 8px 8px 0}
export function mountEffect(root,{reducedMotion=false}={}){const ctl=new AbortController(),signal=ctl.signal,rail=root.querySelector('.rail'),cards=[...root.querySelectorAll('.card')],dots=[...root.querySelectorAll('[data-dot]')];let paused=false,dead=false;const noMotion=()=>reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches||paused;function go(i){if(dead||!cards[i])return;rail.scrollTo({left:cards[i].offsetLeft-cards[0].offsetLeft,behavior:noMotion()?'instant':'smooth'});dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)));}dots.forEach((d,i)=>d.addEventListener('click',()=>go(i),{signal}));rail.addEventListener('scroll',()=>{const x=rail.scrollLeft+cards[0].offsetLeft,i=cards.reduce((b,c,n)=>Math.abs(c.offsetLeft-x)<Math.abs(cards[b].offsetLeft-x)?n:b,0);dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(i===n)));},{passive:true,signal});root.querySelectorAll('.card').forEach(c=>{const p=[...c.querySelectorAll('[data-p]')],s2=[...c.querySelectorAll('[data-s]')],n=[...c.querySelectorAll('[data-n]')];function f(i){p.forEach((x,k)=>x.setAttribute('aria-pressed',String(k===i)));s2.forEach((x,k)=>x.setAttribute('aria-pressed',String(k===i)));n.forEach((x,k)=>x.hidden=k!==i)}p.forEach((x,i)=>x.addEventListener('click',()=>f(i),{signal}));s2.forEach((x,i)=>x.addEventListener('click',()=>f(i),{signal}))});root.dataset.enhanced='true';return{resume(){if(!dead){paused=false;delete root.dataset.paused;}},pause(){paused=true;root.dataset.paused='true';rail.scrollTo({left:rail.scrollLeft,behavior:'instant'});},destroy(){dead=true;ctl.abort();delete root.dataset.paused;delete root.dataset.enhanced;}}}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 用于网页审阅;截图不代表产品或客户效果数据。
交互逻辑
- 截图圆点与文字提示同步。
触摸与无障碍
- 无脚本时保留截图和文字;页面可正常纵向滚动。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
交互与无障碍参考热点是页面审阅提示,不描述链接、产品构造或实际效果。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license手机横幅完整了,为什么上下又多出两条灰边?
图片改成 contain 只解决了裁切,盛它的框仍然很高。我们用 Dawn 15.4.1 的 Image banner 模板和样式,在 390 px 屏宽放入 1200 × 500 的单图。“中等”框高 340 px;只改 contain 后图虽然完整,仍有 178 行灰边。高度改成适应第一张图片,框变为约 163 px,两端完整、灰边为零。
在主题副本打开对应的 Image banner,先把 Banner height 从 Medium 改成 Adapt to first image,保存预览再看。如果必须保留高幅手机横幅,又不想损失主体,另备竖版构图。带长标题、按钮、双图或叠放设置的横幅,要在真实内容下再量框高。
查看对照结果、适用条件与复测代码
390 px/Medium:高 340 px,左右边缘标记被裁掉。
同框改 contain:两端恢复,上下合计 178 行灰色。Adapt:高 163 px,灰行 0。
商家在原帖的追问明确说完整图片上下出现灰边。这里读的是固定版本 Dawn 的模板、两份原始 CSS 和本地截图像素;Shopify 图像滤镜由测试图片代替。没有访问该商家历史主题后台,也没有测其私有 CSS。
WESWOO 实测于 157.0.8103.79 版 Chrome。在空目录中使用 Node.js 22 或更新版本,依次运行 npm install playwright liquidjs@10.21.1、npx playwright install chromium,再运行 node weswoo-dawn-frame.cjs。 脚本会从 Shopify 官方仓库下载固定版本的三个文件并校验 SHA-256。加 --screens 可保存三张读数截图。
提问原帖 · Shopify Dawn 15.4.1 · Image banner · Shopify Dawn 15.4.1 · Image banner CSS · MDN · object-fit
只想在手机上隐藏首页轮播,怎样保证商品图库还在?
把手机媒体查询限定到首页这一个区块的外层 ID。先用检查元素找到自己主题生成的 ID;把例子中的 home-hero 换掉。边界两侧都试一次,同时检查另一个图库入口。
在同页放首页轮播和商品图库两个区块。四个宽度分别读取首个区块和图库链接的可见性,再故意使用全局选择器。
查看对照结果、适用条件与复测代码
390、749 像素只隐藏首页轮播;750、1280 像素均可见。宽泛的 section 规则会把第二个图库也藏起来。
这是另一位商家明确要隐藏轮播的提问。要保留商品完整画面的商家,应看本页的裁剪和适应高度实验。display:none 是否节省下载要看网络记录。
@media (max-width: 749px) {
#shopify-section-home-hero { display: none; }
} WESWOO 实测 Chrome 157.0.8103.79。使用 Node.js 22 或以上版本,在空目录依次运行 npm install playwright → npx playwright install chromium → node weswoo-slideshow-width.cjs。
要判断图片被裁还是传错,先把实际加载的文件单独打开,再比较三个取景框。本站三框用的是同一张网页截图;实验回答布局取景,无法说明某件实物能否放进房间。
宽度从 908 收到 316 px,同一 FMS 截图的三种取景从同时看全三张变为一次看全一张。只切换动态偏好不会改变这个数量。
复现实验与读数
在左右边界内数完整卡片,记录“完整可见数 / 总数”。
- 908 px,两种偏好
- 3 / 3
- 316 px,两种偏好
- 1 / 3
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 打开取景对照 | 同一张 FMS 截图提供局部、中景和全图三种取景。当前一屏能完整看到 1 张。 |
| 1440 / 908 px | 打开取景对照 | 同一张 FMS 截图提供局部、中景和全图三种取景。当前一屏能完整看到 3 张。 |
查看 WESWOO 的实测步骤和结果
先比较前两幅被裁掉的边缘,再看第三幅是否保留整张截图。打开手机宽度,用最后一个圆点到全图,然后点第一个圆点返回。
| 取景或视口 | 实测结果 |
|---|---|
| 局部 / 中景 | 同一文件,cover,分别放大 1.50 / 1.15 倍 |
| 全图 | 同一文件,contain,无额外放大 |
| 1440 px 窗口 / 908 px 预览 | 三幅并排,轨道无需横移 |
| 390 px 窗口 / 316 px 预览 | 选最后一个圆点,轨道从起点横移 438 px |
像素值是当次页面布局的读数。画面素材是项目页面截图;这里只比较取景,不能拿它判断实物尺寸或产品性能。
正在准备预览
特效说明
已验证的结果
这三个画面来自同一张 FMS 项目截图。桌面能并排看局部、中景、全图;手机上点最后一个圆点才能看到全图。第三幅切换了图片适配方式,文件地址相同。
使用说明
窄、中、宽框呈现FMS截图裁切示意,不代表真实断点。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class='fx gallery' lang='en'><div class='rail'><article class='card'><div class='view crop0'><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp' alt='FMS WESWOO project page screenshot' loading='lazy'></div><h3>Detail crop · FMS</h3></article><article class='card'><div class='view crop1'><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp' alt='FMS WESWOO project page screenshot' loading='lazy'></div><h3>Mid-frame · FMS</h3></article><article class='card'><div class='view crop2'><img src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp' alt='FMS WESWOO project page screenshot' loading='lazy'></div><h3>Full image · FMS</h3></article></div><nav class='dots'><button data-dot type='button' aria-label='Screen 1' aria-pressed='true'></button><button data-dot type='button' aria-label='Screen 2' aria-pressed='false'></button><button data-dot type='button' aria-label='Screen 3' aria-pressed='false'></button></nav></section>.gallery.fx{max-width:1100px;margin:auto;padding:24px;background:#f2f0e8;color:#22372e;font:16px/1.6 system-ui,sans-serif}.rail{display:grid;grid-auto-flow:column;grid-auto-columns:calc(100% - 42px);gap:14px;overflow:auto;scroll-snap-type:x mandatory;scrollbar-width:none}.rail::-webkit-scrollbar{display:none}.card{min-width:0;scroll-snap-align:start}.view{height:280px;overflow:hidden;border-radius:12px;background:#fff}.view img{display:block;width:100%;height:100%;object-fit:cover}.view.crop0 img{object-position:50% 10%;transform:scale(1.5);transform-origin:50% 10%}.view.crop1 img{object-position:50% 50%;transform:scale(1.15);transform-origin:50% 50%}.view.crop2{height:auto;aspect-ratio:16/10}.view.crop2 img{object-fit:contain}.card h3{font-size:16px}.dots{display:flex;justify-content:center;gap:12px;margin:14px}.dots button{width:16px;height:16px;border:2px solid #315241;border-radius:50%;background:transparent}.dots [aria-pressed=true]{background:#315241}@media(min-width:760px){.rail{grid-auto-flow:initial;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible}.dots{display:none}}@media(prefers-reduced-motion:reduce){.gallery *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
export function mountEffect(root,{reducedMotion=false}={}){const ctl=new AbortController(),signal=ctl.signal,rail=root.querySelector('.rail'),cards=[...root.querySelectorAll('.card')],dots=[...root.querySelectorAll('[data-dot]')];let paused=false,dead=false;const noMotion=()=>reducedMotion||matchMedia('(prefers-reduced-motion: reduce)').matches||paused;function go(i){if(dead||!cards[i])return;rail.scrollTo({left:cards[i].offsetLeft-cards[0].offsetLeft,behavior:noMotion()?'instant':'smooth'});dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)));}dots.forEach((d,i)=>d.addEventListener('click',()=>go(i),{signal}));rail.addEventListener('scroll',()=>{const x=rail.scrollLeft+cards[0].offsetLeft,i=cards.reduce((b,c,n)=>Math.abs(c.offsetLeft-x)<Math.abs(cards[b].offsetLeft-x)?n:b,0);dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(i===n)));},{passive:true,signal});return{resume(){if(!dead){paused=false;root.dataset.paused='false';}},pause(){paused=true;root.dataset.paused='true';rail.scrollTo({left:rail.scrollLeft,behavior:'instant'});},destroy(){dead=true;ctl.abort();delete root.dataset.paused;}}}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 适用于网页截图浏览和画面讨论;不同视图是同一真实截图的裁切范围。
交互逻辑
- 三张卡片分别显示顶部局部、中间画面和完整截图,手机可滑动选择。
触摸与无障碍
- 无脚本时三种查看范围依然并列可见;完整截图保持原始比例。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
交互与无障碍参考静态视口不能替代真实页面响应式验证。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license固定项目后切上中下区域,再固定区域换项目,把两种操作分开。这里比较网页截图;如需比较型号规格,应回到有单位、版本和来源的商品数据。
换项目之后仍可检查下半部。读到 Viewing lower area 时,才能确认第二步也已执行。
复现实验与读数
在第一张卡选择第二个项目,再选择底部,读取当前画面区域的反馈。
- 908、316 px,两种偏好
- Viewing lower area
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | TERMINO | 选中或展开的控件为“TERMINO / Top / INIU / Top / TERMINO”。 |
| 1440 / 908 px | TERMINO | 选中或展开的控件为“TERMINO / Top / INIU / Top / TERMINO”。 |
正在准备预览
特效说明
使用说明
审阅标题、画面和入口,不呈现虚构商品规格。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class='fx gallery' lang='en'><div class='rail'><article class='card'><figure class='review-shot'><img data-image src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp' alt='SHOKZ WESWOO project page screenshot' loading='lazy'><figcaption data-brand>SHOKZ website page</figcaption></figure><div class='project-switch'><button type='button' data-project='0' aria-pressed='true'>SHOKZ</button><button type='button' data-project='1' aria-pressed='false'>TERMINO</button></div><div class='area-switch'><button type='button' data-area='0' aria-pressed='true'>Top</button><button type='button' data-area='1' aria-pressed='false'>Middle</button><button type='button' data-area='2' aria-pressed='false'>Bottom</button></div><p data-review aria-live='polite'></p></article><article class='card'><figure class='review-shot'><img data-image src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp' alt='INIU WESWOO project page screenshot' loading='lazy'><figcaption data-brand>INIU website page</figcaption></figure><div class='project-switch'><button type='button' data-project='2' aria-pressed='true'>INIU</button><button type='button' data-project='3' aria-pressed='false'>FMS</button></div><div class='area-switch'><button type='button' data-area='0' aria-pressed='true'>Top</button><button type='button' data-area='1' aria-pressed='false'>Middle</button><button type='button' data-area='2' aria-pressed='false'>Bottom</button></div><p data-review aria-live='polite'></p></article><article class='card'><figure class='review-shot'><img data-image src='https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp' alt='TERMINO WESWOO project page screenshot' loading='lazy'><figcaption data-brand>TERMINO website page</figcaption></figure><div class='project-switch'><button type='button' data-project='1' aria-pressed='true'>TERMINO</button><button type='button' data-project='2' aria-pressed='false'>INIU</button></div><div class='area-switch'><button type='button' data-area='0' aria-pressed='true'>Top</button><button type='button' data-area='1' aria-pressed='false'>Middle</button><button type='button' data-area='2' aria-pressed='false'>Bottom</button></div><p data-review aria-live='polite'></p></article></div><nav class='dots'><button data-dot type='button' aria-label='Screen 1' aria-pressed='true'></button><button data-dot type='button' aria-label='Screen 2' aria-pressed='false'></button><button data-dot type='button' aria-label='Screen 3' aria-pressed='false'></button></nav></section>.gallery.fx{max-width:1100px;margin:auto;padding:24px;background:#f2f0e8;color:#22372e;font:16px/1.6 system-ui,sans-serif}.rail{display:grid;grid-auto-flow:column;grid-auto-columns:calc(100% - 42px);gap:14px;overflow:auto;scroll-snap-type:x mandatory;scrollbar-width:none;overscroll-behavior-x:contain}.rail::-webkit-scrollbar{display:none}.card{min-width:0;scroll-snap-align:start}.review-shot{position:relative;aspect-ratio:16/10;overflow:hidden;border-radius:12px;background:#fff;margin:0}.review-shot img{width:100%;height:100%;object-fit:cover;object-position:top}.review-shot figcaption{position:absolute;left:8px;top:8px;padding:5px 10px;border-radius:18px;background:#163629e8;color:white;font-weight:700}.project-switch,.area-switch{display:flex;gap:7px;flex-wrap:wrap;margin:10px 0}.project-switch button,.area-switch button{flex:1 1 auto;min-width:0;min-height:44px;padding:7px 10px;border:1px solid #476453;border-radius:22px;background:#fff;color:#20372b;font:600 14px system-ui;cursor:pointer}.project-switch [aria-pressed=true],.area-switch [aria-pressed=true]{background:#24543e;color:white}.card p{min-height:2.5em;padding:10px 12px;background:white;border-left:3px solid #a65019}.dots{display:flex;justify-content:center;gap:12px;margin:14px}.dots button{width:16px;height:16px;border:2px solid #315241;border-radius:50%;background:transparent}.dots [aria-pressed=true]{background:#315241}.gallery :focus-visible{outline:3px solid #a45d13;outline-offset:3px}@media(min-width:760px){.rail{grid-auto-flow:initial;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible}.dots{display:none}}@media(prefers-reduced-motion:reduce){.gallery *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
export function mountEffect(root,{reducedMotion=false}={}){const ctl=new AbortController(),signal=ctl.signal,rail=root.querySelector('.rail'),cards=[...root.querySelectorAll('.card')],dots=[...root.querySelectorAll('[data-dot]')];let paused=false,dead=false;function go(i){if(dead||!cards[i])return;rail.scrollTo({left:cards[i].offsetLeft-cards[0].offsetLeft,behavior:reducedMotion||paused?'instant':'smooth'});dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)))}dots.forEach((d,i)=>d.addEventListener('click',()=>go(i),{signal}));rail.addEventListener('scroll',()=>{const x=rail.scrollLeft+cards[0].offsetLeft,i=cards.reduce((b,c,n)=>Math.abs(c.offsetLeft-x)<Math.abs(cards[b].offsetLeft-x)?n:b,0);dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)))},{passive:true,signal});const urls=["https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp", "https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp", "https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp", "https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp"];root.querySelectorAll('.card').forEach(card=>{const img=card.querySelector('[data-image]'),brand=card.querySelector('[data-brand]'),projects=[...card.querySelectorAll('[data-project]')],areas=[...card.querySelectorAll('[data-area]')],note=card.querySelector('[data-review]');projects.forEach(btn=>btn.addEventListener('click',()=>{const i=Number(btn.dataset.project);img.src=urls[i];img.alt=btn.textContent+(root.lang==='zh-CN'?' 网站页面截图':' WESWOO project page screenshot');brand.textContent=btn.textContent+(root.lang==='zh-CN'?' 网站页面':' website page');note.textContent=(root.lang==='zh-CN'?'当前项目:':'Current project: ')+btn.textContent;projects.forEach(x=>x.setAttribute('aria-pressed',String(x===btn)))},{signal}));areas.forEach((btn,i)=>btn.addEventListener('click',()=>{areas.forEach(x=>x.setAttribute('aria-pressed',String(x===btn)));note.textContent=(root.lang==='zh-CN'?['查看上部画面','查看中部画面','查看下部画面']:['Viewing upper area','Viewing middle area','Viewing lower area'])[i];img.style.objectPosition=['top','center','bottom'][i]},{signal}))});root.dataset.enhanced='true';return{resume(){if(!dead){paused=false;delete root.dataset.paused}},pause(){paused=true;root.dataset.paused='true';rail.scrollTo({left:rail.scrollLeft,behavior:'instant'})},destroy(){dead=true;ctl.abort();delete root.dataset.paused;delete root.dataset.enhanced}}}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 用于视觉审阅和页面内容讨论;没有虚构商品规格、分值或客户结果。
交互逻辑
- 每张大截图在两个项目间切换,观察按钮调整截图查看区域;手机一张卡片加下一张预览和分页点。
触摸与无障碍
- 无脚本时保留各项目截图、名称和页面审阅提示。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
交互与无障碍参考将原规格表重做为页面内容审阅清单。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license展开三层时核对每层对应截图的哪个区域。要指导顾客拆装实物,应使用经核准的部件图及安装说明;这张网页的分层动画只能说明视觉阅读顺序。
从合拢到展开,再回到合拢,减少动态效果也保留了这个操作。
复现实验与读数
连续两次切换第一幅图的分层按钮,记录是否展开。
- 908、316 px,两种偏好
- 否,再到 是,再到 否
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Separate image layers | 切换第一张 SHOKZ 图后,按钮改为 Reassemble image layers,可从这里合回图层。 |
| 1440 / 908 px | Separate image layers | 切换第一张 SHOKZ 图后,按钮改为 Reassemble image layers,可从这里合回图层。 |
正在准备预览
特效说明
使用说明
配合截图浏览可展开阅读层级,不还原实际DOM。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class='fx gallery' lang='en'><div class='rail'><article class='card'><div class='slices' role='img' aria-label='SHOKZ WESWOO project page screenshot'><span class='slice top' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp)'></span><span class='slice mid' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp)'></span><span class='slice bottom' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp)'></span></div><p class='brand'>SHOKZ · WESWOO project page screenshot</p><button type='button' data-expand aria-expanded='false'>Separate image layers</button></article><article class='card'><div class='slices' role='img' aria-label='FMS WESWOO project page screenshot'><span class='slice top' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp)'></span><span class='slice mid' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp)'></span><span class='slice bottom' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp)'></span></div><p class='brand'>FMS · WESWOO project page screenshot</p><button type='button' data-expand aria-expanded='false'>Separate image layers</button></article><article class='card'><div class='slices' role='img' aria-label='INIU WESWOO project page screenshot'><span class='slice top' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp)'></span><span class='slice mid' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp)'></span><span class='slice bottom' style='--pic:url(https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp)'></span></div><p class='brand'>INIU · WESWOO project page screenshot</p><button type='button' data-expand aria-expanded='false'>Separate image layers</button></article></div><nav class='dots'><button data-dot aria-label='1' aria-pressed='true'></button><button data-dot aria-label='2' aria-pressed='false'></button><button data-dot aria-label='3' aria-pressed='false'></button></nav></section>.gallery.fx{max-width:1100px;margin:auto;padding:24px;background:#f2f0e8;color:#22372e;font:16px/1.6 system-ui,sans-serif}.rail{display:grid;grid-auto-flow:column;grid-auto-columns:calc(100% - 42px);gap:14px;overflow:auto;scroll-snap-type:x mandatory;scrollbar-width:none}.rail::-webkit-scrollbar{display:none}.card{min-width:0;scroll-snap-align:start}.slices{display:grid;grid-template-rows:repeat(3,1fr);gap:0;aspect-ratio:2/1;overflow:visible;border-radius:12px}.slice{display:block;background-image:var(--pic);background-repeat:no-repeat;background-size:100% 300%;background-color:#fff;min-height:0}.slice.top{background-position:top}.slice.mid{background-position:center}.slice.bottom{background-position:bottom}.slices.is-open{gap:9px}.slices.is-open .top{transform:translateY(-3px)}.slices.is-open .bottom{transform:translateY(3px)}.brand{font-weight:700}.card button[data-expand]{min-height:46px;padding:8px 16px;border:1px solid #41594a;border-radius:24px;background:#24543e;color:white;font:600 15px system-ui;cursor:pointer}.card .note{font-size:13px;color:#526157}.dots{display:flex;justify-content:center;gap:12px;margin:14px}.dots button{width:16px;height:16px;border:2px solid #315241;border-radius:50%;background:transparent}.dots [aria-pressed=true]{background:#315241}.gallery :focus-visible{outline:3px solid #a45d13;outline-offset:3px}@media(min-width:760px){.rail{grid-auto-flow:initial;grid-template-columns:repeat(3,minmax(0,1fr));overflow:visible}.dots{display:none}}@media(prefers-reduced-motion:reduce){.slices,.slice{transition:none!important}}
.gallery[data-paused=true] .slices{transition:none!important}.slices,.slice{transition:gap .24s ease}.slices.is-open{gap:8px}
.gallery[data-reduced-motion=true] .slices,.gallery[data-reduced-motion=true] .slice{transition:none!important}/* Adapted layout transition concept from Codrops ScrollBasedLayoutAnimations.
Repository: https://github.com/codrops/ScrollBasedLayoutAnimations
MIT License
Copyright (c) 2009 - 2022 Codrops (https://tympanus.net/codrops)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
export function mountEffect(root,{reducedMotion=false}={}){const c=new AbortController(),s=c.signal,r=root.querySelector('.rail'),cards=[...root.querySelectorAll('.card')],dots=[...root.querySelectorAll('[data-dot]')];let paused=false,dead=false,animations=[];function go(i){if(dead||!cards[i])return;r.scrollTo({left:cards[i].offsetLeft-cards[0].offsetLeft,behavior:reducedMotion||paused?'instant':'smooth'});dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)))}dots.forEach((d,i)=>d.addEventListener('click',()=>go(i),{signal:s}));r.addEventListener('scroll',()=>{const x=r.scrollLeft+cards[0].offsetLeft,i=cards.reduce((b,a,n)=>Math.abs(a.offsetLeft-x)<Math.abs(cards[b].offsetLeft-x)?n:b,0);dots.forEach((d,n)=>d.setAttribute('aria-pressed',String(n===i)))},{passive:true,signal:s});root.querySelectorAll('[data-expand]').forEach(b=>b.addEventListener('click',()=>{animations.forEach(a=>a.cancel());animations=[];const box=b.parentElement.querySelector('.slices'),parts=[...box.querySelectorAll('.slice')],before=parts.map(x=>x.getBoundingClientRect()),open=!box.classList.contains('is-open');box.classList.toggle('is-open',open);b.setAttribute('aria-expanded',String(open));b.textContent=open?(root.lang==='zh-CN'?'合拢画面层次':'Reassemble image layers'):(root.lang==='zh-CN'?'展开画面层次':'Separate image layers');if(!reducedMotion&&!paused)parts.forEach((x,i)=>{const after=x.getBoundingClientRect(),dx=before[i].left-after.left,dy=before[i].top-after.top;if(dx||dy)animations.push(x.animate([{transform:'translate('+dx+'px,'+dy+'px)'},{transform:'translate(0,0)'}],{duration:240,easing:'cubic-bezier(.2,.7,.2,1)'}))})},{signal:s}));root.dataset.enhanced='true';if(reducedMotion)root.dataset.reducedMotion='true';return{resume(){if(!dead){paused=false;delete root.dataset.paused}},pause(){paused=true;root.dataset.paused='true';animations.forEach(a=>a.cancel());animations=[]},destroy(){dead=true;c.abort();animations.forEach(a=>a.cancel());animations=[];root.querySelectorAll('.slices').forEach(x=>x.classList.remove('is-open'));root.querySelectorAll('[data-expand]').forEach(b=>{b.setAttribute('aria-expanded','false');b.textContent=root.lang==='zh-CN'?'展开画面层次':'Separate image layers'});delete root.dataset.reducedMotion;delete root.dataset.paused;delete root.dataset.enhanced}}}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 展示网页截图自身的画面分层,不代表源页面 DOM 或导航结构。
交互逻辑
- 三个切片使用同一张原始截图的上、中、下三分之一像素,合拢时恢复完整页面画面。
触摸与无障碍
- 无脚本时三条切片紧密排列,完整截图仍可辨认。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
Codrops 交互参考实际采用 Codrops ScrollBasedLayoutAnimations 的布局切换/FLIP 思路,三段截图取样对应原图上、中、下像素区域;本例不使用 GSAP,脚本保留完整 MIT 版权声明。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license在手机直接点人物图注,再用键盘切到另一张。检查说明文字和目的地都来自最后选中的卡片,且关掉动效后不需要悬停才能读说明。
默认模式下说明可展开再收起;减少动态效果时它从一开始就展开,两次点选都能继续阅读。
复现实验与读数
对第一张照片连续点选两次,读取其说明是否展开。
- 908、316 px,默认动态
- 否,再到 是,再到 否
- 908、316 px,减少动态效果
- 是,再到 是,再到 是
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
正在准备预览
特效说明
先确定读者要查看什么
先看摄影画面,再点按或悬停显示简短说明。
让图片和交互保持清楚
为图片保留清晰替代文本和明确来源。接入主题时替换成商家有权使用的素材,并检查手机操作、动效偏好和页面滚动。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx lookbook-demo" data-effect="lookbook-reveal"><header class="lb-header"><p class="lb-eyebrow">WESWOO / Visual showcase</p><h2>Real photography.<br>A story worth exploring.</h2><p class="lb-intro">Explore materials, settings and visual storytelling through three portrait photographs. Hover or tap to reveal the description; tap again or press Escape to close. This is a visual interaction demo.</p></header><section class="lb-grid" aria-label="Portrait photography"><button type="button" class="lb-card" aria-expanded="false" aria-controls="lb-detail-1"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22480%22%20height%3D%22640%22%20viewBox%3D%220%200%20480%20640%22%3E%3Crect%20width%3D%22480%22%20height%3D%22640%22%20fill%3D%22%23e8ece6%22%2F%3E%3Ctext%20x%3D%22240%22%20y%3D%22300%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2221%22%20fill%3D%22%2340564b%22%3EReplace%20image%201%3C%2Ftext%3E%3Ctext%20x%3D%22240%22%20y%3D%22338%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2215%22%20fill%3D%22%2340564b%22%3EUse%20your%20own%20licensed%20photograph%3C%2Ftext%3E%3C%2Fsvg%3E" alt="A portrait in warm light"><span class="lb-photo-label">01 / Portrait</span><span class="lb-caption" id="lb-detail-1"><span class="lb-index">PORTRAIT 01</span><strong>A portrait in warm light</strong><p>Warm light and posture shape the composition.</p><span class="lb-action">Tap to close · Interaction demo</span></span></button><button type="button" class="lb-card" aria-expanded="false" aria-controls="lb-detail-2"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22480%22%20height%3D%22640%22%20viewBox%3D%220%200%20480%20640%22%3E%3Crect%20width%3D%22480%22%20height%3D%22640%22%20fill%3D%22%23e8ece6%22%2F%3E%3Ctext%20x%3D%22240%22%20y%3D%22300%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2221%22%20fill%3D%22%2340564b%22%3EReplace%20image%202%3C%2Ftext%3E%3Ctext%20x%3D%22240%22%20y%3D%22338%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2215%22%20fill%3D%22%2340564b%22%3EUse%20your%20own%20licensed%20photograph%3C%2Ftext%3E%3C%2Fsvg%3E" alt="A street fashion portrait against blue architecture"><span class="lb-photo-label">02 / Street style</span><span class="lb-caption" id="lb-detail-2"><span class="lb-index">STREET 02</span><strong>Street style in blue</strong><p>A portrait and blue architecture create a strong colour contrast.</p><span class="lb-action">Tap to close · Interaction demo</span></span></button><button type="button" class="lb-card" aria-expanded="false" aria-controls="lb-detail-3"><img src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22480%22%20height%3D%22640%22%20viewBox%3D%220%200%20480%20640%22%3E%3Crect%20width%3D%22480%22%20height%3D%22640%22%20fill%3D%22%23e8ece6%22%2F%3E%3Ctext%20x%3D%22240%22%20y%3D%22300%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2221%22%20fill%3D%22%2340564b%22%3EReplace%20image%203%3C%2Ftext%3E%3Ctext%20x%3D%22240%22%20y%3D%22338%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2215%22%20fill%3D%22%2340564b%22%3EUse%20your%20own%20licensed%20photograph%3C%2Ftext%3E%3C%2Fsvg%3E" alt="A studio portrait against a dark background"><span class="lb-photo-label">03 / Studio portrait</span><span class="lb-caption" id="lb-detail-3"><span class="lb-index">STUDIO 03</span><strong>A quiet studio portrait</strong><p>A dark backdrop keeps the focus on the portrait.</p><span class="lb-action">Tap to close · Interaction demo</span></span></button></section><div class="lb-dots" aria-label="Gallery pages"><button type="button" data-lb-dot aria-label="1" aria-pressed="true"></button><button type="button" data-lb-dot aria-label="2" aria-pressed="false"></button><button type="button" data-lb-dot aria-label="3" aria-pressed="false"></button></div></section>.lookbook-demo{--ink:#182b27;--paper:#f1eee7;--accent:#b7c7ad;font-family:Arial,"Microsoft YaHei",sans-serif;color:var(--ink);background:var(--paper);padding:clamp(20px,4vw,60px);max-width:1440px;margin:auto;box-sizing:border-box}.lookbook-demo *{box-sizing:border-box}.lb-header{max-width:760px;margin-bottom:32px}.lb-eyebrow{font-size:12px;letter-spacing:.18em;text-transform:uppercase}.lb-header h2{font-size:clamp(30px,4.3vw,62px);font-weight:500;line-height:1.12;margin:16px 0}.lb-intro{font-size:15px;line-height:1.8;max-width:560px}.lb-controls{display:flex;gap:10px;flex-wrap:wrap;margin:20px 0}.lb-controls button{background:transparent;border:1px solid #6d7a71;border-radius:24px;padding:10px 17px;color:inherit;font:inherit;cursor:pointer}.lb-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:20px}.lb-card{position:relative;aspect-ratio:3/4;overflow:hidden;border:0;padding:0;background:#d9ddd3;text-align:left;font:inherit;color:inherit;cursor:pointer;isolation:isolate}.lb-card>img{width:100%;height:100%;object-fit:cover;display:block;transition:transform .7s ease}.lb-photo-label{position:absolute;left:20px;top:20px;z-index:1;background:rgba(241,238,231,.92);padding:7px 10px;font-size:12px}.lb-caption{position:absolute;inset:0;display:flex;flex-direction:column;justify-content:flex-end;padding:clamp(20px,3vw,38px);background:var(--accent);clip-path:polygon(0 100%,17% 100%,29% 100%,43% 100%,58% 100%,73% 100%,87% 100%,100% 100%,100% 100%,0 100%);transition:clip-path .65s cubic-bezier(.2,.75,.2,1);z-index:2}.lb-card:nth-child(2){--accent:#dbc8ad}.lb-card:nth-child(3){--accent:#c4d0d5}.lb-card.is-open .lb-caption{clip-path:polygon(0 0,17% 4%,29% 1%,43% 5%,58% 0,73% 4%,87% 1%,100% 3%,100% 100%,0 100%)}.lb-card.is-open>img{transform:scale(1.045)}.lb-index{font-size:12px;letter-spacing:.1em;margin-bottom:auto;padding-top:12px}.lb-caption strong{font-size:clamp(25px,2.4vw,36px);font-weight:500;line-height:1.15}.lb-caption p{font-size:14px;line-height:1.7;margin:16px 0 24px}.lb-action{border-top:1px solid currentColor;padding-top:14px;font-size:12px}.lb-card:focus-visible,.lb-controls button:focus-visible{outline:3px solid #196f9c;outline-offset:4px}.lb-footnote{font-size:12px;line-height:1.7;margin-top:22px;max-width:760px}.lookbook-demo[data-paused=true] *{transition:none!important;animation-play-state:paused!important}@media(max-width:800px){.lb-grid{display:flex;overflow-x:auto;scroll-snap-type:x mandatory;scrollbar-width:none;padding:4px 4px 12px;gap:14px}.lb-grid::-webkit-scrollbar{display:none}.lb-card{flex:0 0 84%;scroll-snap-align:start}.lb-header h2{font-size:36px}}@media(prefers-reduced-motion:reduce){.lookbook-demo *{transition:none!important;scroll-behavior:auto!important}}
.lookbook-demo[data-reduced-motion=true] *{transition:none!important;scroll-behavior:auto!important}.lb-dots{display:none;justify-content:center;gap:12px;margin:16px 0}.lb-dots button{width:12px;height:12px;border:1px solid var(--ink);border-radius:50%;padding:0;background:transparent;cursor:pointer}.lb-dots button[aria-pressed=true]{background:var(--ink)}.lb-dots button:focus-visible{outline:3px solid #196f9c;outline-offset:4px}@media(max-width:800px){.lb-dots{display:flex}.lb-grid{position:relative}}
.lb-card[data-entry=left] .lb-caption{clip-path:inset(0 100% 0 0)}.lb-card[data-entry=right] .lb-caption{clip-path:inset(0 0 0 100%)}.lb-card[data-entry=top] .lb-caption{clip-path:inset(0 0 100% 0)}.lb-card[data-entry=bottom] .lb-caption{clip-path:inset(100% 0 0 0)}.lb-card.is-open .lb-caption{clip-path:inset(0)}
.lookbook-demo[data-reduced-motion=true] .lb-card .lb-caption{clip-path:inset(0)!important}
.lb-card{aspect-ratio:3/4;min-height:360px}.lb-caption{padding:20px}.lb-caption strong{font-size:clamp(22px,2.4vw,30px)}.lb-caption p{font-size:13px;line-height:1.5;margin:12px 0 16px}@media(max-width:800px){.lb-card{min-height:390px;aspect-ratio:3/4}.lb-caption{padding:20px}.lb-caption strong{font-size:26px}}
/* Adapted from Codrops LookbookHoverEffects js/wipe.js (MIT).
MIT License
Copyright (c) 2009 - 2026 [Codrops](https://codrops.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
function wwEntrySide(look,e){
const r=look.getBoundingClientRect();
const x=Math.min(1,Math.max(0,(e.clientX-r.left)/r.width));
const y=Math.min(1,Math.max(0,(e.clientY-r.top)/r.height));
const gaps={left:x,right:1-x,top:y,bottom:1-y};
return Object.keys(gaps).reduce((a,b)=>gaps[b]<gaps[a]?b:a);
}
export function mountEffect(root, {reducedMotion=false}={}) {
const controller=new AbortController();
const surface=root.matches('.lookbook-demo')?root:root.querySelector('.lookbook-demo');
if(!surface)return{resume(){},pause(){},destroy(){controller.abort();}};
const cards=Array.from(surface.querySelectorAll('.lb-card'));
let paused=false,pinned=null;
surface.dataset.reducedMotion=String(reducedMotion);
function on(node,type,fn){node.addEventListener(type,fn,{signal:controller.signal});}
function reveal(card){cards.forEach(item=>{const open=reducedMotion||item===card;item.classList.toggle('is-open',open);item.setAttribute('aria-expanded',String(open));});}
reveal(null);
cards.forEach(card=>{
on(card,'pointerenter',e=>{if(e.pointerType==='mouse'&&!paused){card.dataset.entry=wwEntrySide(card,e);reveal(card);}});
on(card,'pointerleave',e=>{if(e.pointerType==='mouse'&&!paused)reveal(pinned);});
on(card,'click',()=>{pinned=pinned===card?null:card;reveal(pinned);});
on(card,'keydown',e=>{if(e.key==='Escape'){pinned=null;reveal(null);}});
on(card,'blur',()=>{if(pinned===card)pinned=null;reveal(null);});
});
const grid=surface.querySelector('.lb-grid'),dots=Array.from(surface.querySelectorAll('[data-lb-dot]'));
dots.forEach((dot,index)=>on(dot,'click',()=>{if(!cards[index])return;grid.scrollTo({left:cards[index].offsetLeft-cards[0].offsetLeft,behavior:reducedMotion||paused?'instant':'smooth'});dots.forEach(item=>item.setAttribute('aria-pressed',String(item===dot)));}));
if(grid)on(grid,'scroll',()=>{const nearest=cards.reduce((best,card,index)=>Math.abs(card.offsetLeft-cards[0].offsetLeft-grid.scrollLeft)<Math.abs(cards[best].offsetLeft-cards[0].offsetLeft-grid.scrollLeft)?index:best,0);dots.forEach((dot,index)=>dot.setAttribute('aria-pressed',String(index===nearest)));});
return{resume(){paused=false;surface.dataset.paused='false';},pause(){paused=true;surface.dataset.paused='true';},destroy(){controller.abort();reveal(null);pinned=null;delete surface.dataset.paused;delete surface.dataset.reducedMotion;}};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 摄影、Lookbook 或系列介绍;示例摄影来自 Codrops ColumnScroll 所注明的 Unsplash 素材。
交互逻辑
- 鼠标、键盘和触屏使用同一状态;在线示例展示人物摄影。
触摸与无障碍
- 减少动态时直接显示结果;移动端保留可点击控制与正常页面滚动。
本效果的接入说明
示例图片用于项目展示;接入主题时请选择有权使用的图片,并按主题实际结构测试。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
Codrops 原始交互参考方向判断改编自 Codrops LookbookHoverEffects(MIT)。图片来自 Codrops ColumnScroll,仓库注明来源 Unsplash;不代表客户项目。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license同一批商品按同一顺序切换密度,数清每行列数并记录当前焦点或浏览位置。筛选后切密度若又出现被排除商品,应查列表状态重建。
908 px 时两种密度是两列和四列;316 px 时是一列和两列。同一个“紧凑”按钮并不承诺固定列数。
复现实验与读数
依次选择大图、紧凑、大图,数实际排出的网格列数。
- 908 px,两种偏好
- 2,再到 4,再到 2
- 316 px,两种偏好
- 1,再到 2,再到 1
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Compact | 选中或展开的控件为“Compact”。 |
| 1440 / 908 px | Compact | 选中或展开的控件为“Compact”。 |
查看 WESWOO 的实测步骤和结果
在预览内点 Large 和 Compact,对照每行列数及图注。这里同时记录了浏览器窗口宽度和演示区域的内部宽度,因为侧栏、边距也占空间。
| 窗口 / 预览内宽 | Large 到 Compact |
|---|---|
| 1440 / 908 px | 2 列 到 4 列 |
| 390 / 316 px | 1 列 到 2 列 |
| 两种宽度的图注顺序 | Shokz、Termino、INIU、FMS |
测试开启了减少动态效果。这里可复查列数和内容顺序;买家在较密布局下能否辨认商品,还要用店内实际图片来试。
正在准备预览
特效说明
已验证的结果
把四张图从“大图”换成“紧凑”,到底多看到了几列?在同一页,桌面预览从两列变四列,手机从一列变两列。四张项目图的排列顺序一直相同。
同一批图片,两种浏览方式
大图适合看细节,紧凑视图适合扫一眼全部案例。切换只改变排列,因此读者可以继续看原来的那张图。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx density" lang="en" aria-label="Gallery density demo">
<header><h2>Project gallery</h2><div class="density-switch" role="group" aria-label="Gallery layout">
<button type="button" data-layout="large" aria-pressed="true">Large</button>
<button type="button" data-layout="compact" aria-pressed="false">Compact</button>
</div></header>
<div class="density-grid" data-layout="large"><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" alt="Shokz website screenshot"><figcaption>Shokz</figcaption></figure><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" alt="Termino website screenshot"><figcaption>Termino</figcaption></figure><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" alt="INIU website screenshot"><figcaption>INIU</figcaption></figure><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp" alt="FMS website screenshot"><figcaption>FMS</figcaption></figure></div>
</section>* { box-sizing: border-box; }
.fx {
color: #f8f7ed; background: #18211e; min-height: 270px;
padding: clamp(16px, 4vw, 40px); font: 16px/1.55 system-ui, sans-serif;
}
h2, h3, p, figure { margin: 0; }
h2 { font-size: clamp(1.4rem, 4vw, 2.4rem); line-height: 1.08; letter-spacing: -.035em; }
p { max-width: 58ch; }
button { font: inherit; cursor: pointer; min-height: 44px; }
button:focus-visible { outline: 2px solid #ffe78f; outline-offset: 3px; }
img { display: block; width: 100%; height: auto; }
[hidden] { display: none !important; }
.density { background: #202318; overflow: hidden; }
.density header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; }
.density-switch { display: flex; flex-wrap: wrap; gap: 6px; }
.density-switch button { background: transparent; color: #fff; border: 1px solid #aaa99d; padding: 6px 14px; border-radius: 6px; }
.density-switch [aria-pressed="true"] { color: #202318; background: #ebebc7; border-color: #ebebc7; font-weight: 650; }
.density-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(10px, 2vw, 18px); margin-top: 18px; }
.density-grid[data-layout="compact"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.density-grid figure { min-width: 0; overflow: hidden; border-radius: 8px; background: #323725; transform-origin: left top; }
.density-grid img { aspect-ratio: 2 / 1; object-fit: cover; object-position: 50% 25%; background: #4c513e; }
.density-grid figcaption { padding: 7px 9px; font-size: .8rem; overflow-wrap: anywhere; }
@media (max-width: 540px) {
.density-grid { grid-template-columns: minmax(0, 1fr); }
.density-grid[data-layout="compact"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}/*
MIT License
Copyright (c) 2009 - 2022 [Codrops](https://tympanus.net/codrops)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// Codrops' before/after layout approach, implemented with the Web Animations API.
export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const grid = root.querySelector('.density-grid');
const cards = [...grid.children];
const buttons = [...root.querySelectorAll('button[data-layout]')];
const animations = new Map();
let motion = false;
function stopAnimations() {
animations.forEach(animation => animation.cancel());
animations.clear();
}
function switchLayout(button) {
const target = button.dataset.layout;
if (grid.dataset.layout === target) return;
const before = cards.map(card => card.getBoundingClientRect());
stopAnimations();
grid.dataset.layout = target;
buttons.forEach(control => control.setAttribute('aria-pressed', String(control === button)));
if (!motion || !Element.prototype.animate) return;
cards.forEach((card, index) => {
const first = before[index];
const last = card.getBoundingClientRect();
if (!last.width || !last.height) return;
const animation = card.animate([
{ transform: 'translate(' + (first.left - last.left) + 'px, ' + (first.top - last.top) + 'px) scale('
+ first.width / last.width + ', ' + first.height / last.height + ')' },
{ transform:'none' }
], {duration:380, easing:'cubic-bezier(.2,.75,.25,1)'});
animations.set(card, animation);
animation.onfinish = () => animations.delete(card);
});
}
buttons.forEach(button => button.addEventListener('click', () => switchLayout(button), {signal:lifetime.signal}));
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; stopAnimations(); },
destroy() { lifetime.abort(); stopAnimations(); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 案例图库、款式展示或主题集合页。
交互逻辑
- 先记录现有卡片位置,再切换 CSS Grid 列数,把同一张卡片从旧位置过渡到新位置。
触摸与无障碍
- 手机端切换单列和双列,减少动态模式即时切换。
本效果的接入说明
保留商品卡片的链接和 DOM 顺序,只让布局模式改变列数。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
Codrops 源码与说明Codrops 原版演示布局过渡参考 Iqbal Muthahhary 的教程与 Codrops 开源示例。图片来自 WESWOO 已上线案例。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license固定筛选条件,分别查数据里匹配的 ID、画面上留下的卡片和结果总数。动画完成后有差异时,先查筛选逻辑与过期响应,再查 CSS 是否隐藏了正确卡片。
四件筛到两件后仍能恢复四件。复位也应验一次,否则只看第一次筛选会漏掉商品回不来的错误。
复现实验与读数
从全部商品切换到暖色,再返回全部,读取结果数量。
- 908、316 px,两种偏好
- 4 products,再到 2 products,再到 4 products
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Warm tones | 选择 Warm tones 后,4 件变为 2 件,留下 Rose tee 和 Ochre tee。 |
| 1440 / 908 px | Warm tones | 选择 Warm tones 后,4 件变为 2 件,留下 Rose tee 和 Ochre tee。 |
正在准备预览
特效说明
筛选后,先让结果看得懂
试试 Warm tones 和 Cool tones。少掉的卡片应立即离开阅读顺序,保留的卡片会移动,结果数同时更新。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx filter-demo" lang="en" aria-label="Collection filter preview">
<h2>Shop by color</h2>
<div class="filter-actions" role="group" aria-label="Color family">
<button type="button" data-filter="all" aria-pressed="true">All</button>
<button type="button" data-filter="warm" aria-pressed="false">Warm tones</button>
<button type="button" data-filter="cool" aria-pressed="false">Cool tones</button>
</div>
<p class="filter-count" role="status">4 products</p>
<ul class="filter-cards"><li data-tone="cool"><figure><img src="__WW_VISUAL_1__" alt="Front of a sky T-shirt"><figcaption>Sky blue tee</figcaption></figure></li>
<li data-tone="warm"><figure><img src="__WW_VISUAL_2__" alt="Front of a rose T-shirt"><figcaption>Rose tee</figcaption></figure></li>
<li data-tone="warm"><figure><img src="__WW_VISUAL_3__" alt="Front of a ochre T-shirt"><figcaption>Ochre tee</figcaption></figure></li>
<li data-tone="cool"><figure><img src="__WW_VISUAL_4__" alt="Front of a sage T-shirt"><figcaption>Sage tee</figcaption></figure></li></ul>
</section>* { box-sizing: border-box; }
.fx {
--ink: #1d2825; --paper: #f2f1eb; --edge: #c3cac0;
min-height: 270px; padding: clamp(16px,4vw,40px); color: var(--ink);
background: var(--paper); font: 16px/1.45 system-ui, sans-serif;
}
h2,h3,p,figure { margin: 0; }
h2 { font-size: clamp(1.45rem,4vw,2.75rem); line-height: 1.1; letter-spacing: -.035em; }
img { display: block; max-width: 100%; }
button,input { font: inherit; }
button { min-height: 44px; cursor: pointer; border-radius: 8px; padding: 7px 13px; }
button:focus-visible,input:focus-visible { outline: 2px solid #006d62; outline-offset: 2px; }
[hidden] { display: none !important; }
.filter-demo { --paper: #eef0e8; }
.filter-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 17px; }
.filter-actions button { background: #fdfcf6; color: #233932; border: 1px solid #829489; }
.filter-actions [aria-pressed=true] { background: #214941; color: #fff; border-color: #214941; }
.filter-count { color: #4e6558; margin: 12px 0 8px; }
.filter-cards { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: clamp(8px,2vw,16px); list-style: none; padding: 0; margin: 0; }
.filter-cards li { min-width: 0; border-radius: 10px; background: #fffdf8; overflow: hidden; }
.filter-cards img { width: 100%; height: clamp(90px,20vw,185px); padding: 10px; object-fit: contain; background: #f5f3ed; }
.filter-cards figcaption { padding: 7px 9px; font-size: .875rem; overflow-wrap: anywhere; }
@media (max-width: 630px) { .filter-cards { grid-template-columns: repeat(2,minmax(0,1fr)); } }// Independent CSS Grid and Web Animations adaptation of the Codrops filter demo.
export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const cards = [...root.querySelectorAll('[data-tone]')];
const controls = [...root.querySelectorAll('[data-filter]')];
const count = root.querySelector('.filter-count');
let motion = false;
function stopAnimation() {
for (const card of cards) card.getAnimations?.().forEach(animation => animation.cancel());
}
function applyFilter(button) {
if (button.getAttribute('aria-pressed') === 'true') return;
stopAnimation();
const positions = new Map(cards.filter(card => !card.hidden).map(card => [card, card.getBoundingClientRect()]));
const tone = button.dataset.filter;
let matches = 0;
for (const card of cards) {
card.hidden = tone !== 'all' && tone !== card.dataset.tone;
if (!card.hidden) matches++;
}
controls.forEach(control => control.setAttribute('aria-pressed', String(control === button)));
count.textContent = matches === 1 ? '1 product' : matches + ' products';
if (!motion || !Element.prototype.animate) return;
for (const card of cards.filter(card => !card.hidden)) {
const previous = positions.get(card);
const current = card.getBoundingClientRect();
const from = previous
? {transform:'translate(' + (previous.x-current.x) + 'px,' + (previous.y-current.y) + 'px)'}
: {transform:'translateY(7px)',opacity:0};
card.animate([from,{transform:'none',opacity:1}], {duration:290,easing:'ease-out'});
}
}
controls.forEach(button => button.addEventListener('click', () => applyFilter(button), {signal:lifetime.signal}));
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; stopAnimation(); },
destroy() { lifetime.abort(); stopAnimation(); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 商品集合页、系列页和款式列表。
交互逻辑
- 切换条件后更新可见商品和结果数量,过渡仅作用于仍可见的卡片。
触摸与无障碍
- 手机用可点按的筛选按钮,减少动态时列表即时更新。
本效果的接入说明
真实集合页使用 Shopify 筛选结果作为数据来源,让筛选状态随 URL 保留。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
Codrops 源码与说明Codrops 原版演示筛选交互参考 Codrops Filterable Product Grid,商品图来自 Codrops Product Grid Layout 原版。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license触屏没有持续悬停,给正反面一个明确可点的切换入口。切到背面后再改颜色,核对背图也属于新颜色;只测试单一颜色会漏掉跨变体串图。
两次切换都有对应的状态。图片很相似时,前后标记可以帮助核对状态与所选按钮是否一致。
复现实验与读数
从正面切到背面,再切回正面,记录当前视角的状态文字。
- 908、316 px,两种偏好
- Front view,再到 Back view,再到 Front view
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Back | 原为“Front view”。操作后显示“Back view”。 |
| 1440 / 908 px | Back | 原为“Front view”。操作后显示“Back view”。 |
正在准备预览
特效说明
把另一面交给顾客主动查看
衣服背面可能有图案,设备背面可能有接口。给正反两面各一个清楚的按钮,避免顾客必须猜测手势或等轮播。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx angle-demo" lang="en" aria-label="Product front and back preview">
<div class="angle-copy">
<h2>Sky blue tee</h2>
<p>Check the graphic and the print placement from both sides.</p>
<div class="angle-actions" role="group" aria-label="Product view">
<button type="button" data-side="front" aria-pressed="true">Front</button>
<button type="button" data-side="back" aria-pressed="false">Back</button>
</div>
</div>
<figure class="angle-figure">
<div class="angle-scene">
<div class="angle-flip">
<img class="angle-front" src="__WW_VISUAL_1__" alt="Front of a sky blue T-shirt with a drop graphic">
<img class="angle-back" src="__WW_VISUAL_2__" alt="Back of the same T-shirt with a small Codrops wordmark" aria-hidden="true">
</div>
</div>
<figcaption role="status">Front view</figcaption>
</figure>
</section>* { box-sizing: border-box; }
.fx {
--ink: #1d2825; --paper: #f2f1eb; --edge: #c3cac0;
min-height: 270px; padding: clamp(16px,4vw,40px); color: var(--ink);
background: var(--paper); font: 16px/1.45 system-ui, sans-serif;
}
h2,h3,p,figure { margin: 0; }
h2 { font-size: clamp(1.45rem,4vw,2.75rem); line-height: 1.1; letter-spacing: -.035em; }
img { display: block; max-width: 100%; }
button,input { font: inherit; }
button { min-height: 44px; cursor: pointer; border-radius: 8px; padding: 7px 13px; }
button:focus-visible,input:focus-visible { outline: 2px solid #006d62; outline-offset: 2px; }
[hidden] { display: none !important; }
/* Paired front/back faces adapted from Codrops ProductGridLayout (2013). */
.angle-demo { display: grid; grid-template-columns: minmax(0,.85fr) minmax(0,1.15fr); gap: clamp(14px,4vw,40px); align-items: center; }
.angle-copy p { color: #465c56; margin-top: 9px; max-width: 31ch; }
.angle-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.angle-actions button { background: #fffdfa; border: 1px solid #738b84; color: #1e403a; }
.angle-actions [aria-pressed=true] { background: #214941; border-color: #214941; color: #fff; }
.angle-figure { border-radius: 12px; padding: clamp(10px,3vw,23px); background: #dce9e6; }
.angle-scene { perspective: 950px; }
.angle-flip { display: grid; transform-style: preserve-3d; transition: none; }
.fx[data-motion=on] .angle-flip { transition: transform 380ms cubic-bezier(.2,.7,.2,1); }
.angle-flip.show-back { transform: rotateY(180deg); }
.angle-flip img { grid-area: 1 / 1; width: 100%; height: clamp(165px,31vw,340px); object-fit: contain; backface-visibility: hidden; }
.angle-back { transform: rotateY(180deg); }
.angle-figure figcaption { text-align: center; margin-top: 7px; color: #39564b; font-weight: 650; }
@media (max-width: 650px) { .angle-demo { grid-template-columns: minmax(0,1fr); } }/*
* ProductGridLayout, Copyright (c) 2013 Codrops.
* Adapted from cbpShop.js, released under the MIT license.
* https://github.com/codrops/ProductGridLayout/blob/master/js/cbpShop.js
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const flip = root.querySelector('.angle-flip');
const front = root.querySelector('.angle-front');
const back = root.querySelector('.angle-back');
const label = root.querySelector('figcaption');
const controls = [...root.querySelectorAll('button[data-side]')];
function setSide(button) {
const showBack = button.dataset.side === 'back';
flip.classList.toggle('show-back', showBack);
front.setAttribute('aria-hidden', String(showBack));
back.setAttribute('aria-hidden', String(!showBack));
label.textContent = showBack ? 'Back view' : 'Front view';
controls.forEach(control => control.setAttribute('aria-pressed', String(control === button)));
}
controls.forEach(button => button.addEventListener('click', () => setSide(button), {signal:lifetime.signal}));
return {
resume() { root.dataset.motion = reducedMotion ? 'off' : 'on'; },
pause() { root.dataset.motion = 'off'; },
destroy() { lifetime.abort(); delete root.dataset.motion; }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 服装印花、设备背板和配件连接面。
交互逻辑
- 两张图共用同一尺寸,由按钮决定显示哪一面,当前角度同时用文字标出。
触摸与无障碍
- 触屏和键盘操作相同。减少动态时直接换图。
本效果的接入说明
从当前商品变体取图,替换为对应的正面和背面照片,并为两张图分别写替代文本。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
Codrops 源码与说明Codrops 原版演示正反面切换改编自 Codrops Product Grid Layout 的 MIT 示例代码,使用原版演示中的两张商品图。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license选满两个商品再尝试第三个,读出提示并取消其中一个。若比较表里的型号仍是被取消的旧项,查选中清单与比较表是否读取同一份状态。
只选一件时按钮不可用;选 Sky 和 Rose 后能比较,结果确实包含这两款。
复现实验与读数
先选一件再选第二件,读比较按钮是否可用,再打开结果核对商品名。
- 908、316 px,两种偏好
- 不可用,再到 可用,再到 Sky tee / Rose tee
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Sky | 原为“0 of 2 selected”。操作后显示“1 of 2 selected”。 |
| 1440 / 908 px | Sky | 原为“0 of 2 selected”。操作后显示“1 of 2 selected”。 |
正在准备预览
特效说明
让规格在同一行对得上
选两件商品后打开对比。在同一行读完一个属性,再继续看下一行。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx compare-demo" lang="en" aria-label="Shortlist comparison demo">
<h2>Compare two products</h2>
<p class="intro">Select two tees to compare their sample specifications.</p>
<div class="shortlist" role="group" aria-label="Products to compare"><label><img class="product-photo" src="__WW_VISUAL_1__" alt=""><span><input type="checkbox" data-option="1"> Sky</span></label>
<label><img class="product-photo" src="__WW_VISUAL_2__" alt=""><span><input type="checkbox" data-option="2"> Rose</span></label>
<label><img class="product-photo" src="__WW_VISUAL_3__" alt=""><span><input type="checkbox" data-option="3"> Sage</span></label></div>
<p class="status" role="status" data-selected>0 of 2 selected</p>
<button type="button" class="primary compare-action" data-compare disabled>Compare selected</button>
<div class="panel compare-result" hidden>
<table><caption tabindex="-1">Sample specifications</caption><thead><tr>
<th scope="col">Feature</th><th scope="col" data-name></th><th scope="col" data-name></th>
</tr></thead><tbody>
<tr><th scope="row">Color</th><td data-value></td><td data-value></td></tr>
<tr><th scope="row">Sample fit</th><td data-value></td><td data-value></td></tr>
<tr><th scope="row">Sample price</th><td data-value></td><td data-value></td></tr>
</tbody></table>
<button type="button" data-edit>Edit selection</button>
</div>
</section>* { box-sizing: border-box; }
.fx {
--paper:#f2f3eb; --ink:#20332b; --accent:#205a4c; --edge:#c6cec0; --card:#fffdf8; --mute:#466056;
padding:clamp(14px,3.3vw,34px); min-height:268px; color:var(--ink); background:var(--paper);
font:16px/1.48 system-ui,sans-serif;
}
h2,h3,p,figure,ul,ol,dl,dd,fieldset { margin:0; }
h2 { font-size:clamp(1.38rem,3.8vw,2.55rem); letter-spacing:-.035em; line-height:1.1; }
h3 { font-size:1.12em; }
p { max-width:62ch; }
img { display:block; max-width:100%; }
button,input,select { font:inherit; }
button {
min-height:44px; padding:8px 12px; border:1px solid var(--edge); border-radius:8px;
background:var(--card); color:var(--ink); cursor:pointer; line-height:1.25;
}
button:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible,[tabindex="0"]:focus-visible {
outline:2px solid var(--accent); outline-offset:2px;
}
button:disabled { opacity:.55; cursor:default; }
button[aria-pressed="true"],button.primary { color:white; background:var(--accent); border-color:var(--accent); font-weight:650; }
button:hover:not(:disabled) { border-color:var(--accent); }
[hidden] { display:none !important; }
.intro { margin:8px 0 15px; color:var(--mute); }
.panel { padding:clamp(10px,2.2vw,22px); border:1px solid var(--edge); border-radius:12px; background:var(--card); }
.row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.cols { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:clamp(12px,3vw,28px); align-items:start; }
.product-photo { width:100%; height:clamp(94px,21vw,204px); object-fit:contain; padding:10px; border-radius:10px; background:#e6e9e1; }
.status { color:var(--mute); margin-top:10px; min-height:1.45em; }
@media(max-width:600px){ .cols { grid-template-columns:minmax(0,1fr); } }
.compare-demo { --paper:#eef2ef; }
.shortlist { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:6px; }
.shortlist label { display:flex; flex-direction:column; gap:4px; cursor:pointer; border-radius:10px;
padding:4px; border:1px solid var(--edge); background:var(--card); }
.shortlist label:has(:checked) { border-color:var(--accent); box-shadow:inset 0 0 0 1px var(--accent); }
.shortlist img { height:clamp(58px,14vw,160px); }
.shortlist span { display:flex; gap:3px; align-items:center; min-height:44px; overflow-wrap:anywhere; }
.shortlist input { width:16px; height:16px; flex:none; accent-color:var(--accent); }
.compare-action,.compare-result { margin-top:8px; }
.compare-result table { table-layout:fixed; width:100%; border-collapse:collapse; margin-bottom:12px; font-size:.88em; }
.compare-result caption { text-align:left; font-weight:700; }
.compare-result th,.compare-result td { padding:6px 3px; text-align:left; overflow-wrap:anywhere; border-bottom:1px solid var(--edge); }export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const $ = selector => root.querySelector(selector);
const all = selector => [...root.querySelectorAll(selector)];
const listen = (element, type, handler) => element.addEventListener(type, handler, {signal:lifetime.signal});
const animations = new Map();
let motion = false;
function cancelMotion() {
for (const animation of animations.values()) animation.cancel();
animations.clear();
}
function reveal(element, position = 'translateY(6px)') {
animations.get(element)?.cancel();
if (!motion || !element.animate) return;
const animation = element.animate(
[{transform:position, opacity:.52},{transform:'none', opacity:1}],
{duration:225, easing:'ease-out'}
);
animations.set(element,animation);
animation.onfinish = () => animations.delete(element);
}
const options = all('[data-option]');
const count = $('[data-selected]');
const action = $('[data-compare]');
const panel = $('.compare-result');
const records = {
1:['Sky tee','Sky blue','Regular','$24'],
2:['Rose tee','Rose','Relaxed','$26'],
3:['Sage tee','Sage','Regular','$24']
};
const selected = () => options.filter(option => option.checked);
function update() {
const picks = selected();
count.textContent = picks.length + ' of 2 selected';
action.disabled = picks.length !== 2;
options.forEach(option => { option.disabled = picks.length === 2 && !option.checked; });
}
for (const option of options) listen(option,'change',update);
listen(action,'click',() => {
const picks = selected().map(option => records[option.dataset.option]);
if (picks.length !== 2) return;
all('[data-name]').forEach((cell,i) => { cell.textContent = picks[i][0]; });
all('[data-value]').forEach((cell,i) => { cell.textContent = picks[i%2][Math.floor(i/2)+1]; });
panel.hidden = false;
$('.shortlist').hidden = action.hidden = count.hidden = true;
$('caption').focus({preventScroll:true});
reveal(panel);
});
listen($('[data-edit]'),'click',() => {
panel.hidden = true;
$('.shortlist').hidden = action.hidden = count.hidden = false;
action.focus({preventScroll:true});
});
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; cancelMotion(); },
destroy() { lifetime.abort(); cancelMotion(); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 需要对比款式、材质或技术参数的集合页。
交互逻辑
- 限制选两件,再根据选中商品填充同口径数据。
触摸与无障碍
- 使用普通复选框和语义表格,打开时将焦点移到表格。
本效果的接入说明
用同一组商品元字段生成比较行,推荐支持取消与替换选中商品。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
交互来源Codrops 原版演示选品对比参考 Codrops Product Comparison。商品图来自 Codrops Product Grid Layout。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license系列页提示“加载商品失败”,怎样把两种常见情况分开?
打开网络记录,先看失败请求的状态、内容类型和返回正文。我们让同一份列表依次收到 503、状态 200 的 HTML、以及正确的 JSON。前两次都保留已加载的 A,修复响应后才加入 B;重试同一页没有多出第二个 B。
先确认该接口约定返回 JSON 还是主题 section HTML,再选择解析方法。把失败的状态和类型记在调试记录里,保留原列表;允许重试的响应由使用的接口决定。
查看对照结果、适用条件与复测代码
503 与 200 HTML 分别得到 HTTP 503、Unexpected content type;已显示商品都保留为 A。
有效响应后与再次重试,列表均为 A、B。
本例的接口明确约定 JSON。正常返回 section HTML 的 Shopify 接口不应用此 JSON 判断。原帖未附网络响应,所以不能凭同一句错误文案确定真实商家的故障原因。
async function loadNext(url) {
const res=await fetch(url,{headers:{Accept:'application/json'}});
if(!res.ok)throw Error('HTTP '+res.status);
if(!res.headers.get('content-type')?.includes('application/json'))throw Error('Unexpected content type');
const data=await res.json();
if(!Array.isArray(data.items))throw Error('Missing items');
return data.items;
} WESWOO 实测于 157.0.8103.79 版 Chrome。在空目录中使用 Node.js 22 或更新版本,依次运行 npm install playwright、npx playwright install chromium,再运行 node weswoo-retry.cjs。
点“加载更多”又看到原来的商品,先看请求中的哪两个值?
记下第一次加载和点按钮后的地址,重点核对页码与排序。沿用服务端返回的下一页链接,追加前后对照商品 ID。若下一页响应本身已经重复,应回到数据源排查。
本机服务有两页排序结果。让按钮重发第一页、只保留 page、最后完整沿用响应里的下一页链接。
查看对照结果、适用条件与复测代码
前两种都得到 P1、P1。完整下一页链接得到 P1、P2、P3;最后响应没有下一页,可以停止请求。
这道新原题报告的是重复商品。早先原帖报告等待后出现错误提示,缺少失败响应,两者不能互相解释。此测试未复现原店后台。
WESWOO 实测 Chrome 157.0.8103.79。使用 Node.js 22 或以上版本,在空目录依次运行 npm install playwright → npx playwright install chromium → node weswoo-next-products.cjs。
加载第二页时断开请求,保留第一页可读商品,再重试同一游标两次。示例证明失败时保留旧列表;真实分页仍要按商品 ID 查重,并防止两个成功响应乱序追加。
失败时保住了原有两项,重试后变成四项。成功路径单独跑一遍,测不出失败会不会清空旧列表。
复现实验与读数
已有两项时开启模拟失败并加载,随后解除失败并重试,数每一步的可见结果。
- 908、316 px,两种偏好
- 2,再到 2,再到 4
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Load more | 点击加载后,原有的 Shokz 和 Termino 仍在,列表末尾增加 INIU 和 FMS,状态显示 4 / 4。 |
| 1440 / 908 px | Load more | 点击加载后,原有的 Shokz 和 Termino 仍在,列表末尾增加 INIU 和 FMS,状态显示 4 / 4。 |
正在准备预览
特效说明
加载失败时保留已经看到的内容
打开失败模拟再点 Load more。失败后点 Retry,不需要重新找回此前的两条。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx load-demo" lang="en" aria-label="Load more results demo">
<h2>Load more results</h2>
<p class="intro">See how a list handles loading and retries without losing its current items.</p>
<ul class="results" aria-busy="false"><li><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" alt="Shokz storefront screenshot"><figcaption>Shokz</figcaption></figure></li>
<li><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" alt="Termino storefront screenshot"><figcaption>Termino</figcaption></figure></li>
<li hidden><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" alt="INIU storefront screenshot"><figcaption>INIU</figcaption></figure></li>
<li hidden><figure><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp" alt="FMS storefront screenshot"><figcaption>FMS</figcaption></figure></li></ul>
<p class="status" role="status" data-status>Showing 2 of 4 examples.</p>
<div class="row loader-actions">
<button type="button" class="primary" data-load>Load more</button>
<label><input type="checkbox" data-failure> Simulate a failed request</label>
</div>
</section>* { box-sizing: border-box; }
.fx {
--paper:#f2f3eb; --ink:#20332b; --accent:#205a4c; --edge:#c6cec0; --card:#fffdf8; --mute:#466056;
padding:clamp(14px,3.3vw,34px); min-height:268px; color:var(--ink); background:var(--paper);
font:16px/1.48 system-ui,sans-serif;
}
h2,h3,p,figure,ul,ol,dl,dd,fieldset { margin:0; }
h2 { font-size:clamp(1.38rem,3.8vw,2.55rem); letter-spacing:-.035em; line-height:1.1; }
h3 { font-size:1.12em; }
p { max-width:62ch; }
img { display:block; max-width:100%; }
button,input,select { font:inherit; }
button {
min-height:44px; padding:8px 12px; border:1px solid var(--edge); border-radius:8px;
background:var(--card); color:var(--ink); cursor:pointer; line-height:1.25;
}
button:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible,[tabindex="0"]:focus-visible {
outline:2px solid var(--accent); outline-offset:2px;
}
button:disabled { opacity:.55; cursor:default; }
button[aria-pressed="true"],button.primary { color:white; background:var(--accent); border-color:var(--accent); font-weight:650; }
button:hover:not(:disabled) { border-color:var(--accent); }
[hidden] { display:none !important; }
.intro { margin:8px 0 15px; color:var(--mute); }
.panel { padding:clamp(10px,2.2vw,22px); border:1px solid var(--edge); border-radius:12px; background:var(--card); }
.row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.cols { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:clamp(12px,3vw,28px); align-items:start; }
.product-photo { width:100%; height:clamp(94px,21vw,204px); object-fit:contain; padding:10px; border-radius:10px; background:#e6e9e1; }
.status { color:var(--mute); margin-top:10px; min-height:1.45em; }
@media(max-width:600px){ .cols { grid-template-columns:minmax(0,1fr); } }
.load-demo { --paper:#eeece7; --accent:#52426c; }
.results { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); padding:0; list-style:none; gap:8px; }
.results li { border-radius:9px; overflow:hidden; background:var(--card); }
.results img { width:100%; aspect-ratio:2/1; object-fit:cover; }
.results figcaption { padding:5px 8px; }
.loader-actions { margin-top:8px; }
.loader-actions label { display:flex; align-items:center; gap:5px; min-height:44px; }
.loader-actions input { width:17px; height:17px; }export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const $ = selector => root.querySelector(selector);
const all = selector => [...root.querySelectorAll(selector)];
const listen = (element, type, handler) => element.addEventListener(type, handler, {signal:lifetime.signal});
const animations = new Map();
let motion = false;
function cancelMotion() {
for (const animation of animations.values()) animation.cancel();
animations.clear();
}
function reveal(element, position = 'translateY(6px)') {
animations.get(element)?.cancel();
if (!motion || !element.animate) return;
const animation = element.animate(
[{transform:position, opacity:.52},{transform:'none', opacity:1}],
{duration:225, easing:'ease-out'}
);
animations.set(element,animation);
animation.onfinish = () => animations.delete(element);
}
const list = $('.results');
const load = $('[data-load]');
const failure = $('[data-failure]');
const status = $('[data-status]');
let busy = false;
let finished = false;
let timer;
listen(load,'click',() => {
if (busy || finished) return;
const shouldFail = failure.checked;
busy = true;
load.setAttribute('aria-disabled','true');
failure.disabled = true;
list.setAttribute('aria-busy','true');
status.textContent = 'Loading more results…';
timer = window.setTimeout(() => {
busy = false;
failure.disabled = false;
list.setAttribute('aria-busy','false');
if (shouldFail) {
failure.checked = false;
load.textContent = 'Retry';
status.textContent = 'Could not load more. Your current results are still visible.';
load.removeAttribute('aria-disabled');
return;
}
finished = true;
for (const item of all('.results li[hidden]')) {
item.hidden = false;
reveal(item);
}
load.textContent = 'All results loaded';
load.disabled = true;
status.textContent = 'Showing 4 of 4 examples.';
},480);
});
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; cancelMotion(); },
destroy() { lifetime.abort(); cancelMotion(); window.clearTimeout(timer); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 追加商品、筛选刷新和案例列表。
交互逻辑
- 请求中阻止重复提交,失败保留旧结果,成功后追加。
触摸与无障碍
- 错误和等待由文字状态提示,减少动态时直接显示新结果。
本效果的接入说明
将模拟延时替换成真实分页请求,保留已渲染的商品并提供重试。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
交互来源加载反馈参考 Codrops,预览使用 WESWOO 案例站的真实画面。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license收藏后刷新、退出账户、再在另一设备登录分别验证。本例用当前页面状态切换爱心;界面变色不说明记录已写入账户,也不能承诺跨设备同步。
第二次操作让列表回到空状态。由此能验收藏开关是否可逆;换设备能否保留需要另查存储实现。
复现实验与读数
从空列表保存一张印刷品,再取消收藏,读取列表反馈。
- 908、316 px,两种偏好
- Your list is empty.,再到 Meadow, in bloom · 1 print,再到 Your list is empty.
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | ♡ Save print | 原为“Your list is empty.”。操作后显示“Meadow, in bloom · 1 print”。 |
| 1440 / 908 px | ♡ Save print | 原为“Your list is empty.”。操作后显示“Meadow, in bloom · 1 print”。 |
正在准备预览
特效说明
先让买家看见收藏的去处
打开作品详情时,买家可能还没决定要不要买。保留作品名称和规格,收藏后在原处列出来,方便继续逛。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx wish" lang="en" aria-label="Save a print">
<figure data-stage><img src="__WW_VISUAL_1__" alt="Dandelions swaying in an open meadow"></figure>
<div class="print-info"><p class="eyebrow">FIELD STUDIES / PHOTOGRAPHIC PRINT</p><h2>Meadow, in bloom</h2>
<p class="print-size">Archival print · 30 × 40 cm</p>
<button data-save aria-pressed="false"><span aria-hidden="true">♡</span> Save print</button>
<div class="saved-list"><h3>Saved prints</h3><p data-list role="status">Your list is empty.</p></div></div>
</section>* { box-sizing: border-box; }
.fx {
--paper:#f2f3eb; --ink:#20332b; --accent:#205a4c; --edge:#c6cec0; --card:#fffdf8; --mute:#466056;
padding:clamp(14px,3.3vw,34px); min-height:268px; color:var(--ink); background:var(--paper);
font:16px/1.48 system-ui,sans-serif;
}
h2,h3,p,figure,ul,ol,dl,dd,fieldset { margin:0; }
h2 { font-size:clamp(1.38rem,3.8vw,2.55rem); letter-spacing:-.035em; line-height:1.1; }
h3 { font-size:1.12em; }
p { max-width:62ch; }
img { display:block; max-width:100%; }
button,input,select { font:inherit; }
button {
min-height:44px; padding:8px 12px; border:1px solid var(--edge); border-radius:8px;
background:var(--card); color:var(--ink); cursor:pointer; line-height:1.25;
}
button:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible,[tabindex="0"]:focus-visible {
outline:2px solid var(--accent); outline-offset:2px;
}
button:disabled { opacity:.55; cursor:default; }
button[aria-pressed="true"],button.primary { color:white; background:var(--accent); border-color:var(--accent); font-weight:650; }
button:hover:not(:disabled) { border-color:var(--accent); }
[hidden] { display:none !important; }
.intro { margin:8px 0 15px; color:var(--mute); }
.panel { padding:clamp(10px,2.2vw,22px); border:1px solid var(--edge); border-radius:12px; background:var(--card); }
.row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.cols { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:clamp(12px,3vw,28px); align-items:start; }
.product-photo { width:100%; height:clamp(94px,21vw,204px); object-fit:contain; padding:10px; border-radius:10px; background:#e6e9e1; }
.status { color:var(--mute); margin-top:10px; min-height:1.45em; }
@media(max-width:600px){ .cols { grid-template-columns:minmax(0,1fr); } }
.wish{display:grid;grid-template-columns:1.2fr 1fr;background:#eee9dc;padding:0;color:#273224}
.wish figure{min-height:210px;position:relative;margin:0}.wish figure img{width:100%;height:100%;position:absolute;object-fit:cover}
.print-info{padding:clamp(18px,4vw,42px)}.eyebrow{font:600 11px/1.5 system-ui;letter-spacing:.09em;margin:0 0 12px}
.wish h2{font:normal clamp(26px,4vw,48px)/1.03 Georgia,serif}.print-size{margin:12px 0 17px}.wish button span{font-size:1.35em;vertical-align:middle}
.saved-list{margin-top:22px;padding-top:12px;border-top:1px solid #a6af96}.saved-list h3{font-size:14px}.saved-list p{margin-top:4px}
@media(max-width:520px){.wish{grid-template-columns:1fr}.wish figure{min-height:146px}.print-info{padding:16px}}export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const $ = selector => root.querySelector(selector);
const all = selector => [...root.querySelectorAll(selector)];
const listen = (element, type, handler) => element.addEventListener(type, handler, {signal:lifetime.signal});
const animations = new Map();
let motion = false;
function cancelMotion() {
for (const animation of animations.values()) animation.cancel();
animations.clear();
}
function reveal(element, position = 'translateY(6px)') {
animations.get(element)?.cancel();
if (!motion || !element.animate) return;
const animation = element.animate(
[{transform:position, opacity:.52},{transform:'none', opacity:1}],
{duration:225, easing:'ease-out'}
);
animations.set(element,animation);
animation.onfinish = () => animations.delete(element);
}
const save = $('[data-save]');
listen(save,'click',()=>{
const on = save.getAttribute('aria-pressed') !== 'true';
save.setAttribute('aria-pressed',String(on));
save.querySelector('span').textContent = on ? '♥' : '♡';
$('[data-list]').textContent = on ? 'Meadow, in bloom · 1 print' : 'Your list is empty.';
reveal(save.querySelector('span'),'scale(.7)');
});
return {
resume() { motion = !reducedMotion; const stage = root.querySelector('[data-stage]'); if (stage) reveal(stage); },
pause() { motion = false; cancelMotion(); },
destroy() { lifetime.abort(); cancelMotion(); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 作品详情或商品卡旁。
交互逻辑
- 收藏键和下方清单共用一个状态。
触摸与无障碍
- 按钮支持键盘和触屏,状态也用文字显示。
本效果的接入说明
示例仅在当前预览中保存。正式店铺按商品 ID 或变体 ID 建立收藏记录,并处理保存失败。
上线检查
接入文件
{% comment %} WESWOO example shell. Add ONE effect's HTML inside .fx-slot. {% endcomment %}
{{ 'ww-effects.css' | asset_url | stylesheet_tag }}
<section id="ww-effect-{{ section.id }}" data-ww-effect-section>
<h2>{{ section.settings.heading | escape }}</h2>
<button type="button" data-effect-toggle aria-pressed="false">Play / pause effect</button>
<div class="fx-slot">
{% comment %} Insert the chosen .fx element here; read copy/images from section settings. {% endcomment %}
</div>
</section>
<script type="module" src="{{ 'ww-effect-section.js' | asset_url }}"></script>
{% schema %}
{"name":"WESWOO effect","settings":[{"type":"text","id":"heading","label":"Heading","default":"Our story"}],"presets":[{"name":"WESWOO effect"}]}
{% endschema %}
// Put the chosen example JS in assets/ww-selected-effect.js (rename .mjs to .js).
import {mountEffect} from './ww-selected-effect.js';
const instances=new Map();
function mount(container=document){
const roots=[...(container.matches?.('[data-ww-effect-section]')?[container]:[]),...container.querySelectorAll('[data-ww-effect-section]')];
for(const section of roots){
if(instances.has(section))continue;
const root=section.querySelector('.fx'),button=section.querySelector('[data-effect-toggle]');
if(!root||!button)continue;
const effect=mountEffect(root),events=new AbortController();let playing=false;
const pause=()=>{playing=false;effect.pause();button.setAttribute('aria-pressed','false');};
button.addEventListener('click',()=>{playing=!playing;playing?effect.resume():effect.pause();button.setAttribute('aria-pressed',String(playing));},{signal:events.signal});
const observer=new IntersectionObserver(entries=>{if(!entries[0].isIntersecting)pause();});observer.observe(section);
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:events.signal});
instances.set(section,()=>{observer.disconnect();events.abort();effect.destroy();});
}
}
document.addEventListener('shopify:section:load',event=>mount(event.target));
document.addEventListener('shopify:section:unload',event=>{for(const [section,destroy] of instances)if(section===event.target||event.target.contains(section)){destroy();instances.delete(section);}});
mount();
// Original WESWOO integration. Copy alongside the selected ww-effect-*.js asset.
// The server supplies the asset URL; do not accept a URL from a query parameter.
if (!customElements.get('ww-effect-study')) {
customElements.define('ww-effect-study', class extends HTMLElement {
connectedCallback() {
if (this.events) return;
this.events=new AbortController();this.session={};const session=this.session;
const button=this.querySelector('[data-effect-toggle]');
button.disabled=false;button.setAttribute('aria-pressed','false');this.visible=true;
const preference=matchMedia('(prefers-reduced-motion: reduce)');
const pause=()=>{this.effect?.pause();button.setAttribute('aria-pressed','false');};
this.pause=pause;
button.addEventListener('click',async()=>{
if(this.loading)return;
if(!this.effect){
this.loading=true;button.disabled=true;
try {
const {mountEffect}=await import(this.dataset.moduleUrl);
if(!this.isConnected||this.session!==session)return;
this.effect=mountEffect(this.querySelector('.fx'),{reducedMotion:preference.matches});
} catch {this.querySelector('[data-effect-status]').textContent='The static content is available. Reload to retry motion.';return;}
finally {if(this.session===session){this.loading=false;button.disabled=false;}}
}
if(this.session!==session||document.hidden||!this.visible)return;
const playing=button.getAttribute('aria-pressed')!=='true';
playing?this.effect.resume():this.effect.pause();button.setAttribute('aria-pressed',String(playing));
},{signal:this.events.signal});
document.addEventListener('visibilitychange',()=>{if(document.hidden)pause();},{signal:this.events.signal});
preference.addEventListener('change',()=>{pause();this.effect?.destroy();this.effect=null;},{signal:this.events.signal});
this.observer=new IntersectionObserver(entries=>{this.visible=entries[0].isIntersecting;if(!this.visible)pause();});this.observer.observe(this);
const root=this.querySelector('.fx');
root.querySelectorAll('[data-view]').forEach(trigger=>trigger.addEventListener('click',()=>{const target=root.querySelector('dialog .art'),source=trigger.querySelector('.ww-fx-image');target.querySelector('.ww-fx-image')?.remove();if(source)target.append(source.cloneNode(true));},{signal:this.events.signal}));
// Section unload disconnects this custom element; reconnect mounts one fresh instance.
document.addEventListener('shopify:section:unload',event=>{if(event.target.contains(this))this.teardown();},{signal:this.events.signal});
}
teardown(){this.session=null;this.loading=false;this.observer?.disconnect();this.events?.abort();this.effect?.destroy();this.effect=null;this.events=null;}
disconnectedCallback(){this.teardown();}
});
}
通用壳层需要填入所选效果。每个模块接入一种效果;多种效果需建立明确的注册与 Section 对应关系。
参考资料
来源链接
交互来源Codrops 原版演示收藏动效参考 Codrops Animocons。照片截取自 Codrops InlineHoverReveals 的蒲公英原片段,来源为 Pexels。
Shopify:Sections 架构Shopify:主题编辑器事件与生命周期Shopify:主题性能MDN:Web Animations APIMDN:减少动态效果偏好MDN:iframe 隔离Shopify:图片输出与尺寸Shopify:Section 设置与 SchemaMDN:元素几何测量MDN:图像与文字裁切MDN:原生 dialogShopify:主题无障碍MDN:原生 range 控件示例范围与许可
示例由 WESWOO 和注明的开源作者提供,复制代码时请保留相应许可。在线项目画面与摄影的权利归原权利人;下载文件使用占位图片,接入时请替换为有权使用的素材。
Shopify/dawn · modal / slider base classesShopify/dawn · product media galleryShopify/dawn · license