尺码表与单位切换
打开尺码表,在厘米和英寸之间切换,再切回。盯住同一个尺码同一个部位,比较显示精度和单位文字,别把四舍五入后的数字再当原值换算。
快速切换两个项目,等动画结束后核对按钮名称、选中状态和实际截图。长翻译在静止状态也应读全,不能只有动画中某一帧可见。
直接跳到最后一个项目再回首项,在减少动态效果时仍然有效。检查滚动字样时可以同时检查键盘能否到达同一个项目。
复现实验与读数
从第一项获得焦点开始,依次发送 End 和 Home,记录焦点项目序号。
- 908、316 px,两种偏好
- 4,再到 1
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Termino Aluminium cabinetry website · project screen | 操作后显示“Showing Termino”。 |
| 1440 / 908 px | Termino Aluminium cabinetry website · project screen | 操作后显示“Showing Termino”。 |
正在准备预览
特效说明
滚动标签按钮
先让项目名称清楚可读,再用细微位移提示可交互。触屏直接选择项目,保留页面正常纵向滚动。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx pe-rolling" data-effect="rolling-label" lang="en" aria-label="Rolling label buttons"><p class="fx__eyebrow">REAL WEBSITE SCREENS</p><h3>Rolling labels for project links</h3><p class="fx__lede">Focus, hover over or tap a project button to see its label roll and its screen change.</p><div class="pe-roll-layout"><div class="pe-roll-actions"><button type="button" class="pe-project" data-project="0" aria-pressed="true"><span class="pe-name-wrap"><span class="pe-name">SHOKZ</span><span class="pe-marquee" aria-hidden="true"><span class="pe-marquee__inner"><span>SHOKZ</span><span>SHOKZ</span><span>SHOKZ</span><span>SHOKZ</span></span></span><span class="pe-sub">UK website · project screen</span></span></button><button type="button" class="pe-project" data-project="1" aria-pressed="false"><span class="pe-name-wrap"><span class="pe-name">Termino</span><span class="pe-marquee" aria-hidden="true"><span class="pe-marquee__inner"><span>Termino</span><span>Termino</span><span>Termino</span><span>Termino</span></span></span><span class="pe-sub">Aluminium cabinetry website · project screen</span></span></button><button type="button" class="pe-project" data-project="2" aria-pressed="false"><span class="pe-name-wrap"><span class="pe-name">INIU</span><span class="pe-marquee" aria-hidden="true"><span class="pe-marquee__inner"><span>INIU</span><span>INIU</span><span>INIU</span><span>INIU</span></span></span><span class="pe-sub">Charging products website · project screen</span></span></button><button type="button" class="pe-project" data-project="3" aria-pressed="false"><span class="pe-name-wrap"><span class="pe-name">FMS</span><span class="pe-marquee" aria-hidden="true"><span class="pe-marquee__inner"><span>FMS</span><span>FMS</span><span>FMS</span><span>FMS</span></span></span><span class="pe-sub">Project website · screenshot</span></span><span class="pe-marquee" aria-hidden="true"><span class="pe-marquee__inner"><span>FMS</span><span>FMS</span><span>FMS</span><span>FMS</span></span></span></button></div><div class="pe-roll-preview"><img data-preview="0" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" width="900" height="450" alt="SHOKZ UK website screenshot" ><img data-preview="1" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" width="900" height="450" alt="Termino cabinetry website screenshot" hidden><img data-preview="2" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" width="900" height="450" alt="INIU charging products website screenshot" hidden><div class="pe-caption">Real website screenshot · <span data-caption>SHOKZ</span><img data-preview="3" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp" width="900" height="450" alt="FMS website screenshot" hidden></div></div></div><span class="fx__status" data-status role="status" aria-live="polite"></span></section>/*
* MIT License
*
* Copyright (c) 2009 - 2021 [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.
* Source: https://github.com/codrops/ButtonHoverStyles
*/
.fx{box-sizing:border-box;font-family:inherit;color:#172523;background:#f3f5ef;border-radius:18px;padding:clamp(18px,4vw,38px);overflow:hidden}.fx *{box-sizing:border-box}.fx button,.fx input{font:inherit}.fx h3{font-size:clamp(24px,3vw,34px);line-height:1.2;margin:8px 0}.fx p{line-height:1.6}.fx__eyebrow{font-size:10px;letter-spacing:.14em;font-weight:700}.fx__lede{font-size:13px;color:#536159;max-width:620px}.fx__control{border:1px solid #c4cec1;border-radius:999px;background:transparent;padding:9px 14px;cursor:pointer;color:inherit}.fx__control:focus-visible,.fx button:focus-visible,.fx input:focus-visible{outline:3px solid #356940;outline-offset:3px}.fx__controls{display:flex;gap:8px;flex-wrap:wrap;margin-top:16px}.fx__status{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.fx img{max-width:100%;display:block}.fx [hidden]{display:none!important}@media(prefers-reduced-motion:reduce){.fx *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
.pe-roll-layout,.pe-mag-layout,.pe-menu-panel{display:grid;grid-template-columns:minmax(190px,.75fr) minmax(0,1.25fr);gap:22px;align-items:center}.pe-roll-actions,.pe-mag-list,.pe-menu-items{display:grid;border-top:1px solid #cfd7ca}.pe-project{position:relative;display:flex;align-items:center;justify-content:space-between;gap:12px;text-align:left;width:100%;border:0;border-bottom:1px solid #cfd7ca;background:transparent;padding:15px 10px;color:inherit;cursor:pointer}.pe-project[aria-pressed=true]{background:#e5eadf}.pe-name{font-size:clamp(17px,2vw,24px);font-weight:700}.pe-sub{font-size:10px;color:#536159}.pe-roll-actions .pe-project{overflow:hidden}.pe-roll-actions .pe-name{display:inline-block;transition:transform .24s cubic-bezier(.2,.8,.2,1)}.pe-roll-actions .pe-project:hover .pe-name,.pe-roll-actions .pe-project:focus-visible .pe-name,.pe-roll-actions .pe-project[aria-pressed=true] .pe-name{transform:translateY(-2px)}.pe-roll-preview,.pe-mag-card,.pe-menu-image{min-width:0;border:1px solid #c4cec1;border-radius:12px;background:#fff;overflow:hidden}.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img{width:100%;aspect-ratio:2/1;object-fit:contain}.pe-caption{font-size:10px;color:#536159;padding:10px 14px;margin:0}.pe-caption span{font-weight:700;color:#172523}
.fx.is-paused .pe-roll-actions .pe-name{transition:none!important;transform:none!important}.fx.is-paused .pe-magnet,.fx.is-paused .pe-magnet-label{transition:none!important;transform:none!important}
/* Adapted from ButtonHoverStyles css/base.css .button--atlas marquee (MIT). */
.pe-roll-actions .pe-project{position:relative;overflow:hidden}.pe-roll-actions .pe-name{display:inline-block;position:relative;transition:opacity .15s}.pe-marquee{position:absolute;left:0;top:0;width:100%;height:100%;display:flex;align-items:center;overflow:hidden;pointer-events:none;opacity:0}.pe-marquee span{white-space:nowrap;font-weight:700;font-size:20px;padding:.3rem .8rem}.pe-roll-actions .pe-project:hover .pe-name,.pe-roll-actions .pe-project:focus-visible .pe-name,.pe-roll-actions .pe-project:hover .pe-marquee,.pe-roll-actions .pe-project:focus-visible .pe-marquee,.pe-roll-actions .pe-project:hover .pe-marquee span,.pe-roll-actions .pe-project:focus-visible .pe-marquee span,.pe-roll-actions .pe-project[aria-pressed=true] .pe-marquee span{animation:pe-marquee 1s linear infinite}.pe-marquee span{--move-start:calc(-25% + .25rem);--move-end:calc(-50% + .25rem);transform:translate3d(var(--move-start),0,0)}@keyframes pe-marquee{to{transform:translate3d(var(--move-end),0,0)}}@media(prefers-reduced-motion:reduce){.pe-roll-actions .pe-project:hover .pe-name,.pe-roll-actions .pe-project:focus-visible .pe-name,.pe-roll-actions .pe-project[aria-pressed=true] .pe-name{opacity:1}.pe-marquee{display:none!important}.pe-roll-actions .pe-project:hover .pe-marquee span,.pe-roll-actions .pe-project:focus-visible .pe-marquee span{animation:none!important}}
/* Directly adapts Codrops ButtonHoverStyles css/base.css .button--atlas / .marquee / .marquee__inner. */
.pe-roll-actions .pe-project{position:relative;overflow:hidden}.pe-roll-actions .pe-name{display:inline-block;position:relative;transition:opacity .15s}.pe-marquee{position:absolute;top:0;left:0;width:100%;height:100%;overflow:hidden;pointer-events:none;opacity:0}.pe-marquee__inner{width:max-content;display:flex;align-items:center;position:relative;--offset:1rem;--move-initial:calc(-25% + var(--offset));--move-final:calc(-50% + var(--offset));transform:translate3d(var(--move-initial),0,0);animation:pe-marquee 1s linear infinite;animation-play-state:paused;opacity:0}.pe-marquee span{white-space:nowrap;font-weight:700;font-size:20px;padding:.4rem .8rem}.pe-roll-actions .pe-project:hover .pe-name,.pe-roll-actions .pe-project:focus-visible .pe-name,.pe-roll-actions .pe-project:hover .pe-marquee,.pe-roll-actions .pe-project:focus-visible .pe-marquee,.pe-roll-actions .pe-project:hover .pe-marquee__inner,.pe-roll-actions .pe-project:focus-visible .pe-marquee__inner,@keyframes pe-marquee{0%{transform:translate3d(var(--move-initial),0,0)}100%{transform:translate3d(var(--move-final),0,0)}}.fx.is-paused .pe-marquee__inner{animation-play-state:paused!important;transform:translate3d(0,0,0)}@media(prefers-reduced-motion:reduce){.pe-roll-actions .pe-project:hover .pe-name,.pe-roll-actions .pe-project:focus-visible .pe-name,.pe-roll-actions .pe-project[aria-pressed=true] .pe-name{opacity:1}.pe-marquee{display:none!important}.pe-marquee__inner{animation:none!important}}
.fx.is-paused *, .fx.is-reduced-motion *{scroll-behavior:auto;animation-play-state:paused!important}
.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img,.pe-audit-image img{display:block;width:100%;height:auto;max-height:none;aspect-ratio:2/1;object-fit:contain}
@media(max-width:680px){.pe-roll-layout,.pe-mag-layout{grid-template-columns:minmax(0,1fr);gap:16px}.pe-roll-preview,.pe-mag-card,.pe-menu-image,.pe-audit-image{width:100%;min-width:0}.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img,.pe-audit-image img{height:auto;aspect-ratio:2/1;object-fit:contain}.pe-roll-actions,.pe-mag-list{grid-template-columns:minmax(0,1fr)}.pe-roll-actions .pe-project,.pe-mag-list .pe-project{min-height:60px}}
/* Keep the Codrops marquee rail inside the name slot, never across the helper label. */
.pe-roll-actions .pe-project{display:flex;min-width:0;gap:10px}.pe-name-wrap{position:relative;display:block;flex:0 0 clamp(66px,42%,110px);width:clamp(66px,42%,110px);height:1.5em;min-width:0;overflow:hidden;white-space:nowrap}.pe-name-wrap .pe-name{display:block;opacity:1!important;transition:opacity .15s}.pe-name-wrap .pe-marquee{position:absolute;inset:0;width:100%;height:100%;overflow:hidden;opacity:0;pointer-events:none}.pe-marquee__inner{width:max-content;display:flex;align-items:center;gap:0;white-space:nowrap}.pe-marquee__inner span{flex:none;padding:0 .35rem}.pe-sub{flex:1 1 auto;min-width:0;text-align:right;white-space:normal;line-height:1.35;overflow-wrap:anywhere}.pe-roll-actions .pe-project:hover .pe-name-wrap .pe-name,.pe-roll-actions .pe-project:focus-visible .pe-name-wrap .pe-name{opacity:0!important}.pe-roll-actions .pe-project:hover .pe-name-wrap .pe-marquee,.pe-roll-actions .pe-project:focus-visible .pe-name-wrap .pe-marquee{opacity:1}.pe-roll-actions .pe-project:hover .pe-name-wrap .pe-marquee__inner,.pe-roll-actions .pe-project:focus-visible .pe-name-wrap .pe-marquee__inner{animation-play-state:running;opacity:1}.fx.is-paused .pe-name-wrap .pe-name{opacity:1!important}.fx.is-paused .pe-name-wrap .pe-marquee{display:none!important}.fx.is-paused .pe-name-wrap .pe-marquee__inner{animation:none!important;transform:none!important}@media(max-width:680px){.pe-name-wrap{flex-basis:clamp(66px,36%,110px);width:clamp(66px,36%,110px)}.pe-sub{font-size:10px}}
.fx.is-reduced-motion .pe-name-wrap .pe-name{opacity:1!important}.fx.is-reduced-motion .pe-name-wrap .pe-marquee{display:none!important}.fx.is-reduced-motion .pe-magnet,.fx.is-reduced-motion .pe-magnet-label{transform:none!important;transition:none!important}
/* Shared visual primitives are duplicated intentionally so every effect runs alone in its iframe. */
.pe-project{box-sizing:border-box;position:relative;display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;min-width:0;min-height:60px;padding:13px 10px;border:0;border-bottom:1px solid #cfd7ca;background:transparent;color:#172523;text-align:left;font:inherit;cursor:pointer}.pe-project[aria-pressed=true]{background:#e5eadf}.pe-project:focus-visible{outline:3px solid #356940;outline-offset:-3px}.pe-name{display:block;min-width:0;font-size:clamp(16px,2vw,23px);line-height:1.2;font-weight:700;letter-spacing:-.02em}.pe-sub{display:block;min-width:0;font-size:10px;line-height:1.45;color:#536159}.pe-caption{margin:0;padding:11px 14px;font-size:10px;line-height:1.45;color:#536159}.pe-caption span{font-weight:700;color:#172523}.pe-mag-layout{display:grid;grid-template-columns:minmax(190px,.75fr) minmax(0,1.25fr);gap:22px;align-items:center}.pe-mag-list{display:grid;border-top:1px solid #cfd7ca}.pe-mag-card{min-width:0;overflow:hidden;border:1px solid #c4cec1;border-radius:12px;background:#fff}.pe-mag-image{min-width:0;overflow:hidden}.pe-mag-image img{display:block;width:100%;height:auto;aspect-ratio:2/1;object-fit:contain}.pe-menu-panel{min-width:0}.pe-menu-items{min-width:0}.pe-menu-image img,.pe-roll-preview img,.pe-audit-image img{display:block;width:100%;height:auto;aspect-ratio:2/1;object-fit:contain}@media(max-width:680px){.pe-mag-layout{grid-template-columns:minmax(0,1fr);gap:16px}.pe-mag-list{grid-template-columns:minmax(0,1fr)}.pe-mag-card{width:100%;min-width:0}.pe-project{gap:8px;padding:12px 8px}.pe-sub{font-size:10px}}
@media(max-width:680px){.pe-roll-layout{grid-template-columns:minmax(0,1fr)}.pe-roll-actions{grid-template-columns:minmax(0,1fr)}}
/*
* MIT License
*
* Copyright (c) 2009 - 2021 [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.
* Source: https://github.com/codrops/ButtonHoverStyles
*/
export function mountEffect(root,{reducedMotion=false}={}){
const controller=new AbortController(), signal=controller.signal;
const buttons=[...root.querySelectorAll('[data-project]')], images=[...root.querySelectorAll('[data-preview]')];
const caption=root.querySelector('[data-caption]'), status=root.querySelector('[data-status]'), motion=root.querySelector('[data-motion]');
const toggle=root.querySelector('.pe-menu-toggle'), panel=root.querySelector('.pe-menu-panel');
const controls=[...root.querySelectorAll('button,input')];
const original={className:root.className,style:root.getAttribute('style'),buttons:buttons.map(b=>[b.className,b.getAttribute('aria-pressed')]),images:images.map(i=>[i.className,i.hidden]),caption:caption?.textContent,status:status?.textContent,controls:controls.map(c=>[c,c.value,c.innerHTML,c.getAttribute('aria-expanded'),c.getAttribute('aria-pressed')]),panelHidden:panel?.hidden};
const motionReduced=!!reducedMotion||(typeof window!=='undefined'&&window.matchMedia&&window.matchMedia('(prefers-reduced-motion: reduce)').matches);
let active=0, paused=motionReduced, destroyed=false;
const cleanups=[];
const listen=(node,type,fn,opts={})=>node.addEventListener(type,fn,{...opts,signal});
const announce=s=>{if(status)status.textContent=s};
function select(index,announceChange=false){if(destroyed||!buttons[index]||!images[index])return;active=index;buttons.forEach((b,i)=>{b.setAttribute('aria-pressed',String(i===index));b.classList.toggle('is-active',i===index)});images.forEach((img,i)=>{img.hidden=i!==index;img.classList.toggle('is-active',i===index)});if(caption)caption.textContent=buttons[index].querySelector('.pe-name')?.textContent||'';if(announceChange)announce((root.lang.startsWith('en')?'Showing ':'正在显示 ')+(caption?.textContent||''));}
buttons.forEach((b,i)=>{listen(b,'pointerenter',e=>{if(e.pointerType==='mouse')select(i)});listen(b,'focus',()=>select(i));listen(b,'click',()=>select(i,true));listen(b,'keydown',e=>{let n;if(['ArrowDown','ArrowRight'].includes(e.key))n=(i+1)%buttons.length;else if(['ArrowUp','ArrowLeft'].includes(e.key))n=(i+buttons.length-1)%buttons.length;else if(e.key==='Home')n=0;else if(e.key==='End')n=buttons.length-1;if(n!==undefined){e.preventDefault();buttons[n].focus();select(n,true)}})});
if(motion){motion.setAttribute('aria-pressed',String(paused));motion.textContent=paused?(root.lang.startsWith('en')?'Resume motion':'继续动效'):(root.lang.startsWith('en')?'Pause motion':'暂停动效');listen(motion,'click',()=>{paused=!paused;motion.setAttribute('aria-pressed',String(paused));motion.textContent=paused?(root.lang.startsWith('en')?'Resume motion':'继续动效'):(root.lang.startsWith('en')?'Pause motion':'暂停动效');root.classList.toggle('is-paused',paused);announce(paused?(root.lang.startsWith('en')?'Motion paused':'动效已暂停'):(root.lang.startsWith('en')?'Motion resumed':'动效已继续'))})}
// CSS-only rolling-label treatment adapted from ButtonHoverStyles (MIT);
// transition is interaction-triggered and the control pauses it globally.
select(0);root.classList.toggle('is-reduced-motion',motionReduced);
return {resume(){if(destroyed)return;paused=motionReduced;root.classList.toggle('is-paused',paused);if(motion){motion.setAttribute('aria-pressed','false');motion.textContent=root.lang.startsWith('en')?'Pause motion':'暂停动效'}},pause(){if(destroyed)return;paused=true;root.classList.add('is-paused');const magnet=root.querySelector('[data-magnet]');if(magnet)magnet.style.transform='';if(motion){motion.setAttribute('aria-pressed','true');motion.textContent=root.lang.startsWith('en')?'Resume motion':'继续动效'}},destroy(){if(destroyed)return;destroyed=true;controller.abort();cleanups.forEach(fn=>fn());root.className=original.className;if(original.style===null)root.removeAttribute('style');else root.setAttribute('style',original.style);buttons.forEach((b,i)=>{b.className=original.buttons[i][0];original.buttons[i][1]===null?b.removeAttribute('aria-pressed'):b.setAttribute('aria-pressed',original.buttons[i][1])});images.forEach((img,i)=>{img.className=original.images[i][0];img.hidden=original.images[i][1]});if(caption)caption.textContent=original.caption;if(status)status.textContent=original.status;original.controls.forEach(([c,value,label,expanded,pressed])=>{if(c.matches('input'))c.value=value;if(c.matches('button'))c.innerHTML=label;expanded===null?c.removeAttribute('aria-expanded'):c.setAttribute('aria-expanded',expanded);pressed===null?c.removeAttribute('aria-pressed'):c.setAttribute('aria-pressed',pressed)});if(panel)panel.hidden=original.panelHidden}};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 案例列表、项目目录或服务 CTA 附近。图片均为真实网页截图,名称仅标识对应画面。
交互逻辑
- 点按、键盘或鼠标选择项目时切换截图;按钮文字轻微移动只在交互时发生。无自动播放。
触摸与无障碍
- 减少动态或暂停后保留完整文字、截图选择和正常滚动。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% 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 ButtonHoverStyles,保留 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只用 Tab 和 Enter 触发按钮,再在触屏不移动手指直接点击。吸附位移不应改变命中范围;只有鼠标移动后才出现的关键入口需另设常驻按钮。
鼠标在中心右侧 20 px 时,默认模式下按钮向右移动 6 px,移出后复位。减少动态效果下,相同动作没有添加位移。
复现实验与读数
模拟鼠标在按钮中心右侧 20 px 移动,再移出按钮,读取按钮附加变换。
- 908、316 px,默认动态
- translate3d(6px, 0px, 0px),再到 无
- 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 | Termino Aluminium cabinetry website · project screen | 操作后显示“Showing Termino”。 |
| 1440 / 908 px | Termino Aluminium cabinetry website · project screen | 操作后显示“Showing Termino”。 |
正在准备预览
特效说明
磁吸项目 CTA
磁吸只用于轻量提示,不应让 CTA 难以点击。集成时把本地演示锚点换成真实、确认过的案例目的地。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx pe-magnetic" data-effect="magnetic-cta" lang="en" aria-label="Subtle magnetic button demo"><p class="fx__eyebrow">REAL WEBSITE SCREENS</p><h3>Subtle magnetic CTA</h3><p class="fx__lede">Choose a project, then move the pointer over its button. Tap or use the keyboard to select a project.</p><div class="pe-mag-layout"><div class="pe-mag-list"><button type="button" class="pe-project" data-project="0" aria-pressed="true"><span class="pe-name">SHOKZ</span><span class="pe-sub">UK website · project screen</span></button><button type="button" class="pe-project" data-project="1" aria-pressed="false"><span class="pe-name">Termino</span><span class="pe-sub">Aluminium cabinetry website · project screen</span></button><button type="button" class="pe-project" data-project="2" aria-pressed="false"><span class="pe-name">INIU</span><span class="pe-sub">Charging products website · project screen</span></button><button type="button" class="pe-project" data-project="3" aria-pressed="false"><span class="pe-name">FMS</span><span class="pe-sub">Project website · screenshot</span></button></div><div class="pe-mag-card" id="project-preview"><div class="pe-mag-image"><img data-preview="0" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" width="900" height="450" alt="SHOKZ UK website screenshot" ><img data-preview="1" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" width="900" height="450" alt="Termino cabinetry website screenshot" hidden><img data-preview="2" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" width="900" height="450" alt="INIU charging products website screenshot" hidden><img data-preview="3" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp" width="900" height="450" alt="FMS website screenshot" hidden></div><p class="pe-caption">Real website screenshot · <span data-caption>SHOKZ</span></p><button type="button" class="pe-magnet" data-magnet><span class="pe-magnet-label">View project screen</span></button></div></div><span class="pe-feedback" data-status role="status" aria-live="polite"></span></section>
.fx{box-sizing:border-box;font-family:inherit;color:#172523;background:#f3f5ef;border-radius:18px;padding:clamp(18px,4vw,38px);overflow:hidden}.fx *{box-sizing:border-box}.fx button,.fx input{font:inherit}.fx h3{font-size:clamp(24px,3vw,34px);line-height:1.2;margin:8px 0}.fx p{line-height:1.6}.fx__eyebrow{font-size:10px;letter-spacing:.14em;font-weight:700}.fx__lede{font-size:13px;color:#536159;max-width:620px}.fx__control{border:1px solid #c4cec1;border-radius:999px;background:transparent;padding:9px 14px;cursor:pointer;color:inherit}.fx__control:focus-visible,.fx button:focus-visible,.fx input:focus-visible{outline:3px solid #356940;outline-offset:3px}.fx__controls{display:flex;gap:8px;flex-wrap:wrap;margin-top:16px}.fx__status{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.fx img{max-width:100%;display:block}.fx [hidden]{display:none!important}@media(prefers-reduced-motion:reduce){.fx *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
.pe-mag-card{padding:12px}.pe-mag-image img{border-radius:8px}.pe-magnet{position:relative;display:flex;align-items:center;justify-content:space-between;gap:20px;max-width:270px;margin:14px auto 4px;padding:15px 20px;border-radius:999px;background:#172523;color:#fff;text-decoration:none;font-weight:700;will-change:transform;transition:transform .18s ease,background .2s}.pe-magnet:hover{background:#31513f}.pe-magnet:focus-visible{outline:3px solid #356940;outline-offset:4px}.pe-magnet b{font-size:18px}.pe-note{font-size:10px;color:#657369;text-align:center}.pe-magnetic [data-motion][aria-pressed=true]~.pe-status{display:none}
.fx.is-paused .pe-roll-actions .pe-name{transition:none!important;transform:none!important}.fx.is-paused .pe-magnet,.fx.is-paused .pe-magnet-label{transition:none!important;transform:none!important}
.pe-magnet b{font-size:11px;font-weight:500}
/* MagneticButtons src/js/demo1/buttonCtrl.js trigger threshold and counter-motion (MIT), rewritten for scoped pointer events. */
.pe-magnet-label{display:inline-block;transition:transform .16s ease}.pe-magnet{transition:transform .18s cubic-bezier(.2,.8,.2,1),background .2s}.fx.is-paused .pe-magnet,.fx.is-paused .pe-magnet-label{transform:none!important;transition:none!important}
.fx.is-paused *, .fx.is-reduced-motion *{scroll-behavior:auto;animation-play-state:paused!important}
.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img,.pe-audit-image img{display:block;width:100%;height:auto;max-height:none;aspect-ratio:2/1;object-fit:contain}
@media(max-width:680px){.pe-roll-layout,.pe-mag-layout{grid-template-columns:minmax(0,1fr);gap:16px}.pe-roll-preview,.pe-mag-card,.pe-menu-image,.pe-audit-image{width:100%;min-width:0}.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img,.pe-audit-image img{height:auto;aspect-ratio:2/1;object-fit:contain}.pe-roll-actions,.pe-mag-list{grid-template-columns:minmax(0,1fr)}.pe-roll-actions .pe-project,.pe-mag-list .pe-project{min-height:60px}}
.fx.is-reduced-motion .pe-name-wrap .pe-name{opacity:1!important}.fx.is-reduced-motion .pe-name-wrap .pe-marquee{display:none!important}.fx.is-reduced-motion .pe-magnet,.fx.is-reduced-motion .pe-magnet-label{transform:none!important;transition:none!important}
/* Shared visual primitives are duplicated intentionally so every effect runs alone in its iframe. */
.pe-project{box-sizing:border-box;position:relative;display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;min-width:0;min-height:60px;padding:13px 10px;border:0;border-bottom:1px solid #cfd7ca;background:transparent;color:#172523;text-align:left;font:inherit;cursor:pointer}.pe-project[aria-pressed=true]{background:#e5eadf}.pe-project:focus-visible{outline:3px solid #356940;outline-offset:-3px}.pe-name{display:block;min-width:0;font-size:clamp(16px,2vw,23px);line-height:1.2;font-weight:700;letter-spacing:-.02em}.pe-sub{display:block;min-width:0;font-size:10px;line-height:1.45;color:#536159}.pe-caption{margin:0;padding:11px 14px;font-size:10px;line-height:1.45;color:#536159}.pe-caption span{font-weight:700;color:#172523}.pe-mag-layout{display:grid;grid-template-columns:minmax(190px,.75fr) minmax(0,1.25fr);gap:22px;align-items:center}.pe-mag-list{display:grid;border-top:1px solid #cfd7ca}.pe-mag-card{min-width:0;overflow:hidden;border:1px solid #c4cec1;border-radius:12px;background:#fff}.pe-mag-image{min-width:0;overflow:hidden}.pe-mag-image img{display:block;width:100%;height:auto;aspect-ratio:2/1;object-fit:contain}.pe-menu-panel{min-width:0}.pe-menu-items{min-width:0}.pe-menu-image img,.pe-roll-preview img,.pe-audit-image img{display:block;width:100%;height:auto;aspect-ratio:2/1;object-fit:contain}@media(max-width:680px){.pe-mag-layout{grid-template-columns:minmax(0,1fr);gap:16px}.pe-mag-list{grid-template-columns:minmax(0,1fr)}.pe-mag-card{width:100%;min-width:0}.pe-project{gap:8px;padding:12px 8px}.pe-sub{font-size:10px}}
.pe-magnet{appearance:none;border:0;text-align:left;font-family:inherit;cursor:pointer}.pe-feedback{display:block;min-height:1.5em;margin:8px auto 0;max-width:320px;text-align:center;font-size:12px;line-height:1.5;color:#31513f}.pe-feedback:empty{visibility:hidden}
/*
* MIT License
*
* Copyright (c) 2009 - 2020 [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.
* Source: https://github.com/codrops/MagneticButtons
*/
export function mountEffect(root,{reducedMotion=false}={}){
const controller=new AbortController(), signal=controller.signal;
const buttons=[...root.querySelectorAll('[data-project]')], images=[...root.querySelectorAll('[data-preview]')];
const caption=root.querySelector('[data-caption]'), status=root.querySelector('[data-status]'), motion=root.querySelector('[data-motion]');
const toggle=root.querySelector('.pe-menu-toggle'), panel=root.querySelector('.pe-menu-panel');
const controls=[...root.querySelectorAll('button,input')];
const original={className:root.className,style:root.getAttribute('style'),buttons:buttons.map(b=>[b.className,b.getAttribute('aria-pressed')]),images:images.map(i=>[i.className,i.hidden]),caption:caption?.textContent,status:status?.textContent,controls:controls.map(c=>[c,c.value,c.innerHTML,c.getAttribute('aria-expanded'),c.getAttribute('aria-pressed')]),panelHidden:panel?.hidden};
const motionReduced=!!reducedMotion||(typeof window!=='undefined'&&window.matchMedia&&window.matchMedia('(prefers-reduced-motion: reduce)').matches);
let active=0, paused=motionReduced, destroyed=false;
const cleanups=[];
const listen=(node,type,fn,opts={})=>node.addEventListener(type,fn,{...opts,signal});
const announce=s=>{if(status)status.textContent=s};
function select(index,announceChange=false){if(destroyed||!buttons[index]||!images[index])return;active=index;buttons.forEach((b,i)=>{b.setAttribute('aria-pressed',String(i===index));b.classList.toggle('is-active',i===index)});images.forEach((img,i)=>{img.hidden=i!==index;img.classList.toggle('is-active',i===index)});if(caption)caption.textContent=buttons[index].querySelector('.pe-name')?.textContent||'';if(announceChange)announce((root.lang.startsWith('en')?'Showing ':'正在显示 ')+(caption?.textContent||''));}
buttons.forEach((b,i)=>{listen(b,'pointerenter',e=>{if(e.pointerType==='mouse')select(i)});listen(b,'focus',()=>select(i));listen(b,'click',()=>select(i,true));listen(b,'keydown',e=>{let n;if(['ArrowDown','ArrowRight'].includes(e.key))n=(i+1)%buttons.length;else if(['ArrowUp','ArrowLeft'].includes(e.key))n=(i+buttons.length-1)%buttons.length;else if(e.key==='Home')n=0;else if(e.key==='End')n=buttons.length-1;if(n!==undefined){e.preventDefault();buttons[n].focus();select(n,true)}})});
if(motion){motion.setAttribute('aria-pressed',String(paused));motion.textContent=paused?(root.lang.startsWith('en')?'Resume motion':'继续动效'):(root.lang.startsWith('en')?'Pause motion':'暂停动效');listen(motion,'click',()=>{paused=!paused;motion.setAttribute('aria-pressed',String(paused));motion.textContent=paused?(root.lang.startsWith('en')?'Resume motion':'继续动效'):(root.lang.startsWith('en')?'Pause motion':'暂停动效');root.classList.toggle('is-paused',paused);announce(paused?(root.lang.startsWith('en')?'Motion paused':'动效已暂停'):(root.lang.startsWith('en')?'Motion resumed':'动效已继续'))})}
const magnet=root.querySelector('[data-magnet]'), magnetLabel=root.querySelector('.pe-magnet-label');
if(magnet){const move=e=>{if(paused||e.pointerType!=='mouse')return;const r=magnet.getBoundingClientRect(),cx=r.left+r.width/2,cy=r.top+r.height/2,dx=e.clientX-cx,dy=e.clientY-cy,dist=Math.hypot(dx,dy),trigger=r.width*.7;if(dist<trigger){const x=dx*.3,y=dy*.3;magnet.style.transform='translate3d('+x+'px,'+y+'px,0)';if(magnetLabel)magnetLabel.style.transform='translate3d('+(-x*.6)+'px,'+(-y*.6)+'px,0)'}else leave()};const leave=()=>{magnet.style.transform='';if(magnetLabel)magnetLabel.style.transform=''};listen(magnet,'pointermove',move);listen(magnet,'pointerleave',leave);listen(magnet,'blur',leave);listen(magnet,'click',()=>announce((root.lang.startsWith('en')?'Showing the ':'正在显示 ')+(caption?.textContent||'')+(root.lang.startsWith('en')?' website screen':'官网画面')));cleanups.push(leave)}
select(0);root.classList.toggle('is-reduced-motion',motionReduced);
return {resume(){if(destroyed)return;paused=motionReduced;root.classList.toggle('is-paused',paused);if(motion){motion.setAttribute('aria-pressed','false');motion.textContent=root.lang.startsWith('en')?'Pause motion':'暂停动效'}},pause(){if(destroyed)return;paused=true;root.classList.add('is-paused');const magnet=root.querySelector('[data-magnet]'), magnetLabel=root.querySelector('.pe-magnet-label');if(magnet)magnet.style.transform='';if(magnetLabel)magnetLabel.style.transform='';if(motion){motion.setAttribute('aria-pressed','true');motion.textContent=root.lang.startsWith('en')?'Resume motion':'继续动效'}},destroy(){if(destroyed)return;destroyed=true;controller.abort();cleanups.forEach(fn=>fn());root.className=original.className;if(original.style===null)root.removeAttribute('style');else root.setAttribute('style',original.style);buttons.forEach((b,i)=>{b.className=original.buttons[i][0];original.buttons[i][1]===null?b.removeAttribute('aria-pressed'):b.setAttribute('aria-pressed',original.buttons[i][1])});images.forEach((img,i)=>{img.className=original.images[i][0];img.hidden=original.images[i][1]});if(caption)caption.textContent=original.caption;if(status)status.textContent=original.status;original.controls.forEach(([c,value,label,expanded,pressed])=>{if(c.matches('input'))c.value=value;if(c.matches('button'))c.innerHTML=label;expanded===null?c.removeAttribute('aria-expanded'):c.setAttribute('aria-expanded',expanded);pressed===null?c.removeAttribute('aria-pressed'):c.setAttribute('aria-pressed',pressed)});if(panel)panel.hidden=original.panelHidden}};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 项目展示或案例 CTA。示例不宣称客户转化效果,链接集成前应替换为确认过的目的地。
交互逻辑
- 仅鼠标移动时对按钮提供有边界的磁吸反馈;点击后在原位显示当前所选项目的官网画面反馈,不导航、不滚动。键盘与触屏使用原生按钮行为。
触摸与无障碍
- 减少动态、暂停、触屏或不支持指针时保持静态;页面滚动未被拦截。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% 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 MagneticButtons,保留 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鼠标迅速越过相邻两项,然后在手机点同一项。若最后停留的是 B 而预览仍显示 A,检查异步图片完成顺序;图注和最终目标链接都要跟最后一次选择一致。
鼠标和焦点都能切换当前项目。用键盘检查最后一步,可以发现只监听悬停的实现漏掉了哪类顾客。
复现实验与读数
从第一项开始,模拟鼠标进入第二项,再让第三项获得键盘焦点,读取当前项目序号。
- 908、316 px,两种偏好
- 1,再到 2,再到 3
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | 02 Termino Aluminium kitchens · Project screen | 操作后显示“Showing Termino website screen”。 |
| 1440 / 908 px | 02 Termino Aluminium kitchens · Project screen | 操作后显示“Showing Termino website screen”。 |
正在准备预览
特效说明
预览要回答列表中的疑问
例如案例目录列出住宅、办公与零售项目,旁边的图片让人先辨认空间类型,再决定读哪一个。标题、图片和目标页应来自同一条记录,避免文字指向一个项目而预览另一个。预览可以补充判断,但名称和入口本身也要足够清楚。
选择预览与进入页面分清楚
示例把鼠标进入、键盘聚焦和点击接到同一选择函数,更新图片与当前状态。它展示的是选择预览,不代表已经完成项目导航。主题可保留独立的真实链接,让触屏第一次选择后仍有明确进入方式;图片区域预留尺寸,换图时列表位置不跟着跳,减少动态时直接显示选中图。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx ww-hover" lang="en" aria-label="Project screen previews">
<div class="ww-hover__intro"><p class="ww-hover__eyebrow">SELECTED PROJECTS</p><h3>Explore the pages behind the projects.</h3><p>Hover, focus or select a project to view its website screen.</p></div>
<div class="ww-hover__layout">
<div class="ww-hover__list" aria-label="Select a project">
<button type="button" class="ww-hover__item is-active" data-project="0" aria-pressed="true"><span class="ww-hover__number">01</span><span><strong>SHOKZ</strong><small>UK website · Project screen</small></span><span class="ww-hover__mark" aria-hidden="true"></span></button>
<button type="button" class="ww-hover__item" data-project="1" aria-pressed="false"><span class="ww-hover__number">02</span><span><strong>Termino</strong><small>Aluminium kitchens · Project screen</small></span><span class="ww-hover__mark" aria-hidden="true"></span></button>
<button type="button" class="ww-hover__item" data-project="2" aria-pressed="false"><span class="ww-hover__number">03</span><span><strong>INIU</strong><small>Charging products · Project screen</small></span><span class="ww-hover__mark" aria-hidden="true"></span></button>
</div>
<div class="ww-hover__preview"><div class="ww-hover__chrome" aria-hidden="true"><i></i><i></i><i></i><span>WESWOO / PROJECT VIEW</span></div><div class="ww-hover__stage"><img class="is-active" data-preview="0" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" width="900" height="450" alt="SHOKZ UK website project screen"><img data-preview="1" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" width="900" height="450" alt="Termino aluminium kitchen website project screen" hidden><img data-preview="2" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" width="900" height="450" alt="INIU charging product website project screen" hidden></div><div class="ww-hover__caption"><span data-caption>SHOKZ</span><span>Website screenshot</span></div></div>
</div><span class="ww-hover__sr" data-status role="status" aria-live="polite"></span>
</section>
.ww-hover{--ink:#172523;--accent:#d7f768;--line:#d3d9d2;padding:clamp(20px,4vw,48px);background:#f3f5ef;color:var(--ink);border-radius:20px;font-family:inherit;overflow:hidden}.ww-hover *{box-sizing:border-box}.ww-hover__intro{max-width:650px;margin-bottom:30px}.ww-hover__eyebrow{font-size:11px;letter-spacing:.16em;font-weight:700}.ww-hover h3{font-size:clamp(24px,3vw,38px);line-height:1.22;margin:12px 0}.ww-hover__intro>p:last-child{font-size:14px;line-height:1.7;color:#55635e}.ww-hover__layout{display:grid;grid-template-columns:minmax(210px,.75fr) minmax(0,1.5fr);gap:36px;align-items:center}.ww-hover__list{border-top:1px solid var(--line)}.ww-hover__item{width:100%;display:flex;align-items:center;gap:18px;text-align:left;background:transparent;border:0;border-bottom:1px solid var(--line);padding:24px 10px;color:inherit;cursor:pointer;font:inherit;transition:background .22s,padding .22s}.ww-hover__item.is-active{background:#e5eadf;padding-left:20px}.ww-hover__number{font-size:11px;color:#657369;align-self:flex-start;padding-top:5px}.ww-hover__item strong{display:block;font-size:clamp(22px,3vw,32px);letter-spacing:-.035em;font-weight:650}.ww-hover__item small{display:block;margin-top:8px;font-size:11px;line-height:1.5;color:#536159}.ww-hover__mark{margin-left:auto;flex:0 0 9px;height:9px;border-radius:50%;border:1px solid #657369}.ww-hover__item.is-active .ww-hover__mark{background:var(--ink);border-color:var(--ink)}.ww-hover__item:focus-visible{outline:3px solid #356940;outline-offset:-3px}.ww-hover__preview{min-width:0;border:1px solid #bcc7bb;border-radius:12px;background:#fff;overflow:hidden;box-shadow:0 16px 35px #162b1a12;transform:translateY(var(--preview-y,0px));transition:transform .3s ease}.ww-hover__chrome{height:34px;background:#e5eadf;display:flex;align-items:center;gap:5px;padding:0 12px}.ww-hover__chrome i{width:5px;height:5px;background:#899889;border-radius:50%}.ww-hover__chrome span{margin-left:auto;font-size:8px;letter-spacing:.08em;color:#52624f}.ww-hover__stage{aspect-ratio:2/1;position:relative;background:#dce2d6}.ww-hover__stage img{width:100%;height:100%;object-fit:contain;display:block;animation:ww-hover-reveal .32s ease both}.ww-hover__stage img[hidden]{display:none}.ww-hover__caption{display:flex;justify-content:space-between;gap:12px;padding:14px 16px;font-size:10px;color:#5c685c}.ww-hover__caption [data-caption]{font-weight:700;color:var(--ink)}.ww-hover__sr{position:absolute;width:1px;height:1px;padding:0;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.ww-hover.is-reduced-motion *{animation:none!important;transition:none!important}.ww-hover.is-paused .ww-hover__preview{transform:none}.ww-hover.is-paused *{animation:none!important;transition:none!important}@keyframes ww-hover-reveal{from{opacity:.55;transform:scale(1.025)}to{opacity:1;transform:scale(1)}}@media(max-width:680px){.ww-hover__layout{grid-template-columns:1fr;gap:22px}.ww-hover__list{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));border:1px solid var(--line);border-radius:8px;overflow:hidden}.ww-hover__item{display:block;padding:14px 10px!important;min-width:0;border-bottom:0;border-right:1px solid var(--line)}.ww-hover__item:last-child{border-right:0}.ww-hover__number{display:block;margin-bottom:8px}.ww-hover__item strong{font-size:clamp(17px,4.7vw,25px)}.ww-hover__item small{font-size:10px}.ww-hover__mark{display:none}.ww-hover__preview{transform:none}.ww-hover__caption{font-size:10px;padding:12px}}@media(prefers-reduced-motion:reduce){.ww-hover *{animation:none!important;transition:none!important}.ww-hover__preview{transform:none}}
// Uses project screenshots hosted on WESWOO; no external runtime.
export function mountEffect(root,{reducedMotion=false}={}){
const buttons=[...root.querySelectorAll('[data-project]')];
const images=[...root.querySelectorAll('[data-preview]')];
const caption=root.querySelector('[data-caption]');
const status=root.querySelector('[data-status]');
const controller=new AbortController();
const originalClass=root.className;
const originalStyle=root.style.cssText;
const original=buttons.map(button=>({className:button.className,pressed:button.getAttribute('aria-pressed')}));
const originalImages=images.map(img=>({className:img.className,hidden:img.hidden}));
const originalCaption=caption.textContent;
let selected=0,paused=false,destroyed=false;
root.classList.toggle('is-reduced-motion',reducedMotion);
function select(index,announce=false){
if(destroyed||!buttons[index]||!images[index])return;
selected=index;
buttons.forEach((button,i)=>{button.classList.toggle('is-active',i===index);button.setAttribute('aria-pressed',String(i===index));});
images.forEach((img,i)=>{img.hidden=i!==index;img.classList.toggle('is-active',i===index);});
const name=buttons[index].querySelector('strong').textContent;
caption.textContent=name;
root.style.setProperty('--preview-y',(!paused&&!reducedMotion?(index-1)*5:0)+'px');
if(announce)status.textContent=root.lang.startsWith('en')?'Showing '+name+' website screen':'正在显示 '+name+' 官网画面';
}
buttons.forEach((button,index)=>{
button.addEventListener('pointerenter',event=>{if(event.pointerType==='mouse')select(index);},{signal:controller.signal});
button.addEventListener('focus',()=>select(index),{signal:controller.signal});
button.addEventListener('click',()=>select(index,true),{signal:controller.signal});
button.addEventListener('keydown',event=>{
let next;
if(event.key==='ArrowDown'||event.key==='ArrowRight')next=(index+1)%buttons.length;
if(event.key==='ArrowUp'||event.key==='ArrowLeft')next=(index+buttons.length-1)%buttons.length;
if(event.key==='Home')next=0;
if(event.key==='End')next=buttons.length-1;
if(next!==undefined){event.preventDefault();buttons[next].focus();select(next,true);}
},{signal:controller.signal});
});
select(0);
// Manual selection stays available while paused; no autonomous playback exists.
return {
pause(){if(destroyed)return;paused=true;root.classList.add('is-paused');root.style.setProperty('--preview-y','0px');},
resume(){if(destroyed)return;paused=false;root.classList.remove('is-paused');select(selected);},
destroy(){if(destroyed)return;destroyed=true;controller.abort();root.className=originalClass;root.style.cssText=originalStyle;buttons.forEach((button,i)=>{button.className=original[i].className;if(original[i].pressed===null)button.removeAttribute('aria-pressed');else button.setAttribute('aria-pressed',original[i].pressed);});images.forEach((img,i)=>{img.className=originalImages[i].className;img.hidden=originalImages[i].hidden;});caption.textContent=originalCaption;status.textContent='';}
};
}
接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 案例、系列导览或品牌内容 Section;标题、目标链接与预览图片使用同一个 block 数据。
交互逻辑
- 鼠标进入、键盘聚焦和点击共用 select 函数,更新选中状态、图片标识和替代文本。真实图片使用 image_url / image_tag,并预留尺寸。
触摸与无障碍
- 手机用点击选择,不依赖悬停;有减少动态效果偏好时直接替换内容。预览只是辅助,真实跳转另有明确链接。
上线检查
接入文件
{% 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;本例代码独立编写,画面来自 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关掉自定义指针,再仅用触屏或键盘找到“查看项目”。跟随光标的文字可帮助有鼠标的人,购买或浏览入口仍需在没有光标时可见可用。
减少动态效果时跟随标签关闭,点选仍能报告 INIU 已选中。这两步可分别验收装饰和功能。
复现实验与读数
模拟鼠标进入画面中心再点选,先记录跟随标签是否启用,再读点选反馈。
- 908、316 px,默认动态
- 是,再到 INIU project screen selected. Add your own destination when integrating.
- 908、316 px,减少动态效果
- 否,再到 INIU project screen selected. Add your own destination when integrating.
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
正在准备预览
特效说明
提示跟随,入口本身不消失
案例封面可以在鼠标经过时出现“查看项目”的标签,但项目名称和链接仍应在固定位置可见。这样没有鼠标的人也能理解用途。跟随标签适合为大图入口补充提示,不适合承载唯一的价格、说明或下一步,否则指针离开后信息就没了。
标签属于卡片的局部坐标
示例将鼠标位置换算到卡片内部,并按标签半径限制边界,让它不会跑出图外。标签不接收指针事件,普通光标保留;底层演示按钮响应点击并只更新状态。接入主题时把演示按钮换成具有真实目的地的链接,图片与目标来自同一内容记录。触屏保留普通入口,减少动态时可把提示固定显示。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="cursor-label"><small>20 / CONTEXT AT THE POINTER</small><button type="button" class="cursor-target" aria-label="Explore the INIU website project screen"><span class="art" data-art="3" aria-hidden="true"></span><span class="cursor-caption">INIU / PROJECT SCREEN</span><span class="cursor-badge" aria-hidden="true">VIEW<br>STUDY</span></button><p class="hint" role="status">Hover to move the label; tap or press Enter to select.</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}}
.fx{padding:25px;background:#111625}.cursor-target{padding:0;border:0;border-radius:0;position:relative;overflow:hidden;text-align:left;background:transparent!important}.cursor-target .art{display:block;height:360px}.cursor-caption{position:absolute;left:20px;bottom:20px;border-radius:99px;background:#e6e9f0;color:#1b2240;padding:10px 16px;font-size:10px;letter-spacing:.08em}.cursor-badge{display:grid;place-content:center;position:absolute;left:var(--cx,50%);top:var(--cy,50%);transform:translate(-50%,-50%) scale(.6);width:95px;height:95px;border-radius:50%;background:#d8fc75;color:#16202a;font:11px/1.2 Arial,sans-serif;letter-spacing:.1em;text-align:center;opacity:0;pointer-events:none;transition:opacity .2s,transform .25s}.fx[data-label=true] .cursor-badge{opacity:1;transform:translate(-50%,-50%) scale(1)}.fx[data-reduced-motion=true] .cursor-badge{display:none}@media(max-width:500px){.cursor-target .art{height:330px}.cursor-caption{font-size:8px;left:12px;bottom:12px}}
/* 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 target=root.querySelector('.cursor-target');let frame=0,x=0,y=0;
on(target,'pointermove',event=>{if(!active||reduced||event.pointerType!=='mouse')return;const r=target.getBoundingClientRect();x=Math.max(52,Math.min(r.width-52,event.clientX-r.left));y=Math.max(52,Math.min(r.height-52,event.clientY-r.top));root.dataset.label='true';if(!frame)frame=requestAnimationFrame(()=>{frame=0;root.style.setProperty('--cx',x+'px');root.style.setProperty('--cy',y+'px');});});
on(target,'pointerleave',()=>root.dataset.label='false');on(target,'click',()=>{if(active)root.querySelector('[role=status]').textContent='INIU project screen selected. Add your own destination when integrating.';});stop=()=>{cancelAnimationFrame(frame);frame=0;root.dataset.label='false';};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_3 输出画面,link 设置提供真实去向。接入例将演示按钮替换为正常链接,不依靠浮动标签完成操作。
交互逻辑
- pointermove 计算卡片内坐标并按标签半径收边,通过 CSS 变量移动标签;标签 pointer-events:none,不遮挡底层链接。只处理 mouse 指针,不隐藏全站光标。
触摸与无障碍
- 触摸、键盘与减少动态使用底部固定提示及正常链接。浮动提示 aria-hidden,避免两次读到相同动作;离开和暂停时隐藏。
本效果的接入说明
文件:复制下方 sections/ww-effect-cursor-label.liquid;将本项 JavaScript 原样保存为 assets/ww-effect-cursor-label.js,并复制本页共用的 assets/ww-effect-studio.js。Section 已内含限定在 .ww-fx-host 的 CSS。
数据:案例或系列导览 Section;image_3 输出画面,link 设置提供真实去向。接入例将演示按钮替换为正常链接,不依靠浮动标签完成操作。
初始化:播放时才加载所选模块;每个 Section 独立保存实例。离屏、切换标签页和偏好变化会暂停,Section 卸载会断开观察与监听。
交付边界:这是具体的主题接入示例;滚动类保留画布内滚动模型。若改为整页驱动,须按前文逻辑重新计算 Section 区间。请在复制主题中替换图片、翻译控件并核验主题样式和实际设备。
上线检查
接入文件
{% comment %}
WESWOO original Section example. Copy assets/ww-effect-cursor-label.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="cursor-label" id="WWEffect-{{ section.id }}" data-module-url="{{ 'ww-effect-cursor-label.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="cursor-label"><small>20 / CONTEXT AT THE POINTER</small><a class="cursor-target" href="{{ section.settings.link | default: routes.all_products_collection_url }}" aria-label="{{ section.settings.heading_1 | escape }}"><span class="art" data-art="3" aria-hidden="true">{% 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 class="cursor-caption">{{ section.settings.heading_1 | escape }}</span><span class="cursor-badge" aria-hidden="true">VIEW<br>STUDY</span></a><p class="hint" role="status">Hover to move the label; tap or press Enter to select.</p></section>
</ww-effect-study>
<script type="module" src="{{ 'ww-effect-studio.js' | asset_url }}"></script>
{% stylesheet %}
.ww-fx-host[data-effect-type="cursor-label"] *{box-sizing:border-box}.ww-fx-host[data-effect-type="cursor-label"]{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}.ww-fx-host[data-effect-type="cursor-label"] button,.ww-fx-host[data-effect-type="cursor-label"] input{font:inherit}.ww-fx-host[data-effect-type="cursor-label"] 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="cursor-label"] button:hover{background:#ffffff15}.ww-fx-host[data-effect-type="cursor-label"] button:focus-visible,.ww-fx-host[data-effect-type="cursor-label"] a:focus-visible,.ww-fx-host[data-effect-type="cursor-label"] input:focus-visible,.ww-fx-host[data-effect-type="cursor-label"] [tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.ww-fx-host[data-effect-type="cursor-label"] .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="cursor-label"] .fx h2,.ww-fx-host[data-effect-type="cursor-label"] .fx h3,.ww-fx-host[data-effect-type="cursor-label"] .fx p{margin:0}.ww-fx-host[data-effect-type="cursor-label"] .fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.ww-fx-host[data-effect-type="cursor-label"] .fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.ww-fx-host[data-effect-type="cursor-label"] .fx>small{position:relative;z-index:2;align-self:start}.ww-fx-host[data-effect-type="cursor-label"] .fx p{max-width:46ch}.ww-fx-host[data-effect-type="cursor-label"] .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="cursor-label"] .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="cursor-label"] .art:before,.ww-fx-host[data-effect-type="cursor-label"] .art:after{content:none!important}.ww-fx-host[data-effect-type="cursor-label"] .hint{font-size:11px;color:#b5b8ad}.ww-fx-host[data-effect-type="cursor-label"] .controls{display:flex;gap:8px;flex-wrap:wrap}.ww-fx-host[data-effect-type="cursor-label"] .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="cursor-label"] .spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.ww-fx-host[data-effect-type="cursor-label"] .fx [hidden]{display:none!important}.ww-fx-host[data-effect-type="cursor-label"] .fx[data-playing=false] *{animation-play-state:paused!important}.ww-fx-host[data-effect-type="cursor-label"] .fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.ww-fx-host[data-effect-type="cursor-label"] .fx a{color:inherit;text-underline-offset:4px}.ww-fx-host[data-effect-type="cursor-label"] .fx[data-reduced-motion=true] *,.ww-fx-host[data-effect-type="cursor-label"] .fx[data-reduced-motion=true] *:before,.ww-fx-host[data-effect-type="cursor-label"] .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="cursor-label"] .fx{padding:22px;min-height:460px;gap:18px}.ww-fx-host[data-effect-type="cursor-label"] .fx h2{font-size:43px}.ww-fx-host[data-effect-type="cursor-label"] .fx>small{font-size:8px}.ww-fx-host[data-effect-type="cursor-label"] .art{min-height:215px}.ww-fx-host[data-effect-type="cursor-label"] .scroller{height:355px}.ww-fx-host[data-effect-type="cursor-label"] .fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){.ww-fx-host[data-effect-type="cursor-label"] *,.ww-fx-host[data-effect-type="cursor-label"] *:before,.ww-fx-host[data-effect-type="cursor-label"] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}.ww-fx-host[data-effect-type="cursor-label"] .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="cursor-label"] .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="cursor-label"] .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="cursor-label"] .fx{padding:25px;background:#111625}.ww-fx-host[data-effect-type="cursor-label"] .cursor-target{padding:0;border:0;border-radius:0;position:relative;overflow:hidden;text-align:left;background:transparent!important}.ww-fx-host[data-effect-type="cursor-label"] .cursor-target .art{display:block;height:360px}.ww-fx-host[data-effect-type="cursor-label"] .cursor-caption{position:absolute;left:20px;bottom:20px;border-radius:99px;background:#e6e9f0;color:#1b2240;padding:10px 16px;font-size:10px;letter-spacing:.08em}.ww-fx-host[data-effect-type="cursor-label"] .cursor-badge{display:grid;place-content:center;position:absolute;left:var(--cx,50%);top:var(--cy,50%);transform:translate(-50%,-50%) scale(.6);width:95px;height:95px;border-radius:50%;background:#d8fc75;color:#16202a;font:11px/1.2 Arial,sans-serif;letter-spacing:.1em;text-align:center;opacity:0;pointer-events:none;transition:opacity .2s,transform .25s}.ww-fx-host[data-effect-type="cursor-label"] .fx[data-label=true] .cursor-badge{opacity:1;transform:translate(-50%,-50%) scale(1)}.ww-fx-host[data-effect-type="cursor-label"] .fx[data-reduced-motion=true] .cursor-badge{display:none}@media(max-width:500px){.ww-fx-host[data-effect-type="cursor-label"] .cursor-target .art{height:330px}.ww-fx-host[data-effect-type="cursor-label"] .cursor-caption{font-size:8px;left:12px;bottom:12px}}
.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 cursor-label",
"settings": [
{
"type": "text",
"id": "heading_1",
"label": "Heading 1",
"default": "ORBIT — EXPLORE THE STUDY"
},
{
"type": "image_picker",
"id": "image_3",
"label": "Image 3"
},
{
"type": "url",
"id": "link",
"label": "Destination"
}
],
"presets": [
{
"name": "WW cursor-label"
}
]
}
{% 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,两种偏好
- 否,再到 是,再到 否
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
正在准备预览
特效说明
先看懂组合表达的主题
例如以材料、制作与成品三张图介绍一件家具,组合应让读者辨认它们的关系。悬停或聚焦可以展开画面,点击固定后便于停下来观看。它适合品牌开场,不适合把三个独立商品的购买入口藏进会移动的碎片中;项目链接可以在下方保持稳定。
图片移动围绕同一个区域
示例以容器内的指针位置驱动相反方向的小幅位移,并把连续变化合并到一次画面更新。接入时由图片与标题设置组成同一主题,给长标题留出不受遮挡的空间。手机上优先展示清楚的组合,减少动态时回到静态排布;固定与关闭都应有直观回应。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx" data-effect="pointer-mosaic"><small>19 / EXPLORE THE BRAND</small><div class="mosaic-scene"><div class="mosaic-column" aria-hidden="true"><div class="art" data-art="1"></div><div class="art" data-art="2"></div></div><button type="button" class="mosaic-trigger" aria-pressed="false">A NEW<br><em>PERSPECTIVE.</em><span>Hover or tap to explore</span></button><div class="mosaic-column" aria-hidden="true"><div class="art" data-art="3"></div><div class="art" data-art="1"></div></div></div><p class="hint" role="status">A local hero composition. The normal pointer stays visible.</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}}
.fx{background:#e8e5db;color:#26291f}.fx small,.hint{color:#626950}.mosaic-scene{position:relative;min-height:340px;display:grid;align-items:center;grid-template-columns:1fr 1.6fr 1fr;gap:20px}.mosaic-column{display:grid;gap:17px;transition:transform .45s,opacity .45s;opacity:.55}.mosaic-column:first-child{transform:translate(-30px,30px) rotate(-9deg)}.mosaic-column:last-child{transform:translate(30px,-30px) rotate(9deg)}.mosaic-column .art{min-height:145px;border-radius:4px}.mosaic-column .art:nth-child(2){height:100px;min-height:100px}.mosaic-trigger{position:relative;z-index:1;border:0;padding:25px 0;font-size:clamp(33px,5.5vw,64px);line-height:.95;font-weight:750;letter-spacing:-.065em;background:transparent!important;color:#26291f}.mosaic-trigger em{font:italic 1em Georgia,serif}.mosaic-trigger span{display:block;font:10px Arial,sans-serif;letter-spacing:.03em;margin-top:24px}.fx[data-exploring=true] .mosaic-column{opacity:1;transform:translate(var(--mx,0px),var(--my,0px)) rotate(0)}.fx[data-exploring=true] .mosaic-column:last-child{transform:translate(calc(-1 * var(--mx,0px)),calc(-1 * var(--my,0px))) rotate(0)}@media(max-width:500px){.mosaic-scene{grid-template-columns:1fr 2fr 1fr;gap:0;margin:0 -12px}.mosaic-column .art{min-height:140px}.mosaic-trigger{font-size:32px}}.fx[data-reduced-motion=true] .mosaic-column{opacity:1;transform:none!important}
@media(max-width:500px){.mosaic-trigger em{font-size:25px}}
/* 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 trigger=root.querySelector('.mosaic-trigger');let pinned=false,frame=0,x=0,y=0;
function reflect(value){root.dataset.exploring=String(value);trigger.setAttribute('aria-pressed',String(value));}
on(trigger,'pointerenter',event=>{if(active&&event.pointerType==='mouse')reflect(true);});on(trigger,'focus',()=>{if(active)reflect(true);});
on(trigger,'click',()=>{if(active){pinned=!pinned;reflect(pinned);root.querySelector('[role=status]').textContent=pinned?'Composition expanded. Tap again to settle.':'Composition settled.';}});
on(root,'pointermove',event=>{if(!active||reduced||event.pointerType!=='mouse')return;const r=root.getBoundingClientRect();x=(event.clientX-r.left-r.width/2)/r.width*30;y=(event.clientY-r.top-r.height/2)/r.height*30;if(!frame)frame=requestAnimationFrame(()=>{frame=0;root.style.setProperty('--mx',x+'px');root.style.setProperty('--my',y+'px');});});
on(trigger,'pointerleave',()=>reflect(pinned));on(trigger,'blur',()=>reflect(pinned));stop=()=>{cancelAnimationFrame(frame);frame=0;pinned=false;reflect(false);root.style.removeProperty('--mx');root.style.removeProperty('--my');};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,标题来自 heading_1 / heading_2。图片只作为装饰,真实作品入口保留在稳定链接区。
交互逻辑
- 悬停或聚焦展开两列,点击可保持或收起;鼠标位置按容器宽高归一,限制在 30px 范围,再用同一帧更新 --mx / --my,两列取相反符号。
触摸与无障碍
- 触摸通过真实按钮展开;键盘有稳定按钮名称。减少动态时静态展开;离开、失焦或暂停复位,原生指针始终保留。
本效果的接入说明
文件:复制下方 sections/ww-effect-pointer-mosaic.liquid;将本项 JavaScript 原样保存为 assets/ww-effect-pointer-mosaic.js,并复制本页共用的 assets/ww-effect-studio.js。Section 已内含限定在 .ww-fx-host 的 CSS。
数据:品牌首屏 Section;图片来自 image_1—image_3,标题来自 heading_1 / heading_2。图片只作为装饰,真实作品入口保留在稳定链接区。
初始化:播放时才加载所选模块;每个 Section 独立保存实例。离屏、切换标签页和偏好变化会暂停,Section 卸载会断开观察与监听。
交付边界:这是具体的主题接入示例;滚动类保留画布内滚动模型。若改为整页驱动,须按前文逻辑重新计算 Section 区间。请在复制主题中替换图片、翻译控件并核验主题样式和实际设备。
上线检查
接入文件
{% comment %}
WESWOO original Section example. Copy assets/ww-effect-pointer-mosaic.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="pointer-mosaic" id="WWEffect-{{ section.id }}" data-module-url="{{ 'ww-effect-pointer-mosaic.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="pointer-mosaic"><small>19 / EXPLORE THE BRAND</small><div class="mosaic-scene"><div class="mosaic-column" aria-hidden="true"><div 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 %}</div><div 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 %}</div></div><button type="button" class="mosaic-trigger" aria-pressed="false">{{ section.settings.heading_1 | escape }}<br><em>{{ section.settings.heading_2 | escape }}</em><span>Hover or tap to explore</span></button><div class="mosaic-column" aria-hidden="true"><div 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 %}</div><div 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 %}</div></div></div><p class="hint" role="status">A local hero composition. The normal pointer stays visible.</p></section>
</ww-effect-study>
<script type="module" src="{{ 'ww-effect-studio.js' | asset_url }}"></script>
{% stylesheet %}
.ww-fx-host[data-effect-type="pointer-mosaic"] *{box-sizing:border-box}.ww-fx-host[data-effect-type="pointer-mosaic"]{margin:0;background:#111211;color:#f4f0e7;font:14px/1.55 Arial,Helvetica,sans-serif}.ww-fx-host[data-effect-type="pointer-mosaic"] button,.ww-fx-host[data-effect-type="pointer-mosaic"] input{font:inherit}.ww-fx-host[data-effect-type="pointer-mosaic"] 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="pointer-mosaic"] button:hover{background:#ffffff15}.ww-fx-host[data-effect-type="pointer-mosaic"] button:focus-visible,.ww-fx-host[data-effect-type="pointer-mosaic"] a:focus-visible,.ww-fx-host[data-effect-type="pointer-mosaic"] input:focus-visible,.ww-fx-host[data-effect-type="pointer-mosaic"] [tabindex]:focus-visible{outline:3px solid #c6fc6b;outline-offset:4px}.ww-fx-host[data-effect-type="pointer-mosaic"] .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="pointer-mosaic"] .fx h2,.ww-fx-host[data-effect-type="pointer-mosaic"] .fx h3,.ww-fx-host[data-effect-type="pointer-mosaic"] .fx p{margin:0}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx h2{font-size:clamp(36px,7vw,82px);font-weight:750;letter-spacing:-.065em;line-height:.98}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx small{letter-spacing:.18em;color:#c2c3b9;font-size:10px}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx>small{position:relative;z-index:2;align-self:start}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx p{max-width:46ch}.ww-fx-host[data-effect-type="pointer-mosaic"] .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="pointer-mosaic"] .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="pointer-mosaic"] .art:before,.ww-fx-host[data-effect-type="pointer-mosaic"] .art:after{content:none!important}.ww-fx-host[data-effect-type="pointer-mosaic"] .hint{font-size:11px;color:#b5b8ad}.ww-fx-host[data-effect-type="pointer-mosaic"] .controls{display:flex;gap:8px;flex-wrap:wrap}.ww-fx-host[data-effect-type="pointer-mosaic"] .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="pointer-mosaic"] .spacer{height:120px;display:grid;place-items:center;color:#bfc1b5;font-size:11px;letter-spacing:.04em}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx [hidden]{display:none!important}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx[data-playing=false] *{animation-play-state:paused!important}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx button[aria-pressed=true]{background:#c6fc6b;color:#171a12}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx a{color:inherit;text-underline-offset:4px}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx[data-reduced-motion=true] *,.ww-fx-host[data-effect-type="pointer-mosaic"] .fx[data-reduced-motion=true] *:before,.ww-fx-host[data-effect-type="pointer-mosaic"] .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="pointer-mosaic"] .fx{padding:22px;min-height:460px;gap:18px}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx h2{font-size:43px}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx>small{font-size:8px}.ww-fx-host[data-effect-type="pointer-mosaic"] .art{min-height:215px}.ww-fx-host[data-effect-type="pointer-mosaic"] .scroller{height:355px}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx:after{font-size:7px;right:16px}}
@media(prefers-reduced-motion:reduce){.ww-fx-host[data-effect-type="pointer-mosaic"] *,.ww-fx-host[data-effect-type="pointer-mosaic"] *:before,.ww-fx-host[data-effect-type="pointer-mosaic"] *:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}}.ww-fx-host[data-effect-type="pointer-mosaic"] .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="pointer-mosaic"] .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="pointer-mosaic"] .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="pointer-mosaic"] .fx{background:#e8e5db;color:#26291f}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx small,.ww-fx-host[data-effect-type="pointer-mosaic"] .hint{color:#626950}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-scene{position:relative;min-height:340px;display:grid;align-items:center;grid-template-columns:1fr 1.6fr 1fr;gap:20px}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-column{display:grid;gap:17px;transition:transform .45s,opacity .45s;opacity:.55}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-column:first-child{transform:translate(-30px,30px) rotate(-9deg)}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-column:last-child{transform:translate(30px,-30px) rotate(9deg)}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-column .art{min-height:145px;border-radius:4px}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-column .art:nth-child(2){height:100px;min-height:100px}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-trigger{position:relative;z-index:1;border:0;padding:25px 0;font-size:clamp(33px,5.5vw,64px);line-height:.95;font-weight:750;letter-spacing:-.065em;background:transparent!important;color:#26291f}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-trigger em{font:italic 1em Georgia,serif}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-trigger span{display:block;font:10px Arial,sans-serif;letter-spacing:.03em;margin-top:24px}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx[data-exploring=true] .mosaic-column{opacity:1;transform:translate(var(--mx,0px),var(--my,0px)) rotate(0)}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx[data-exploring=true] .mosaic-column:last-child{transform:translate(calc(-1 * var(--mx,0px)),calc(-1 * var(--my,0px))) rotate(0)}@media(max-width:500px){.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-scene{grid-template-columns:1fr 2fr 1fr;gap:0;margin:0 -12px}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-column .art{min-height:140px}.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-trigger{font-size:32px}}.ww-fx-host[data-effect-type="pointer-mosaic"] .fx[data-reduced-motion=true] .mosaic-column{opacity:1;transform:none!important}
@media(max-width:500px){.ww-fx-host[data-effect-type="pointer-mosaic"] .mosaic-trigger em{font-size:25px}}
.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 pointer-mosaic",
"settings": [
{
"type": "text",
"id": "heading_1",
"label": "Heading 1",
"default": "A NEW"
},
{
"type": "text",
"id": "heading_2",
"label": "Heading 2",
"default": "PERSPECTIVE."
},
{
"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 pointer-mosaic"
}
]
}
{% 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顾客若问“两种饰面在实物上有什么差别”,此处调整的是截图亮度和对比度。需要实物判断时展示同光源的授权样片、材料规格和可订货号。
亮度从 100 到 130,再精确回到 100。截图对比前先复位,可避免把观察工具调出的差异误认成原图差异。
复现实验与读数
把第一个亮度滑块调到上限,再复位,读取滑块数值。
- 908、316 px,两种偏好
- 100,再到 130,再到 100
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Termino Aluminium cabinetry website · project screen | 操作后显示“Showing Termino”。 |
| 1440 / 908 px | Termino Aluminium cabinetry website · project screen | 操作后显示“Showing Termino”。 |
正在准备预览
特效说明
检查网页视觉层级
切换 SHOKZ、Termino、INIU 或 FMS 网页截图,调节明暗、对比和放大倍率,观察页面画面。控件只改变预览显示。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx pe-audit" data-effect="material-explorer" lang="en" aria-label="Website screenshot hierarchy check"><p class="fx__eyebrow">REAL WEBSITE SCREENS</p><h3>Website screenshot hierarchy check</h3><p class="fx__lede">Switch website screenshots and adjust brightness, contrast and zoom to inspect visual hierarchy. </p><div class="pe-audit-grid"><div class="pe-audit-image"><img data-preview="0" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" width="900" height="450" alt="SHOKZ UK website screenshot" ><img data-preview="1" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/termino-preview.webp" width="900" height="450" alt="Termino cabinetry website screenshot" hidden><img data-preview="2" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/iniu-preview.webp" width="900" height="450" alt="INIU charging products website screenshot" hidden><img data-preview="3" src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/fms-preview.webp" width="900" height="450" alt="FMS project website screenshot" hidden><div class="pe-crosshair" aria-hidden="true"></div></div><div class="pe-audit-controls"><div class="pe-audit-projects"><button type="button" class="pe-project" data-project="0" aria-pressed="true"><span class="pe-name">SHOKZ</span><span class="pe-sub">UK website · project screen</span></button><button type="button" class="pe-project" data-project="1" aria-pressed="false"><span class="pe-name">Termino</span><span class="pe-sub">Aluminium cabinetry website · project screen</span></button><button type="button" class="pe-project" data-project="2" aria-pressed="false"><span class="pe-name">INIU</span><span class="pe-sub">Charging products website · project screen</span></button><button type="button" class="pe-project" data-project="3" aria-pressed="false"><span class="pe-name">FMS</span><span class="pe-sub">Project website · screenshot</span></button></div><label>Brightness <input type="range" min="70" max="130" value="100" data-filter="brightness" aria-label="Brightness"></label><label>Contrast <input type="range" min="70" max="150" value="100" data-filter="contrast" aria-label="Contrast"></label><label>Zoom <input type="range" min="100" max="160" value="100" data-filter="zoom" aria-label="Zoom"></label><button type="button" class="fx__control" data-reset>Reset display</button></div></div><span class="fx__status" data-status role="status" aria-live="polite"></span></section>
.fx{box-sizing:border-box;font-family:inherit;color:#172523;background:#f3f5ef;border-radius:18px;padding:clamp(18px,4vw,38px);overflow:hidden}.fx *{box-sizing:border-box}.fx button,.fx input{font:inherit}.fx h3{font-size:clamp(24px,3vw,34px);line-height:1.2;margin:8px 0}.fx p{line-height:1.6}.fx__eyebrow{font-size:10px;letter-spacing:.14em;font-weight:700}.fx__lede{font-size:13px;color:#536159;max-width:620px}.fx__control{border:1px solid #c4cec1;border-radius:999px;background:transparent;padding:9px 14px;cursor:pointer;color:inherit}.fx__control:focus-visible,.fx button:focus-visible,.fx input:focus-visible{outline:3px solid #356940;outline-offset:3px}.fx__controls{display:flex;gap:8px;flex-wrap:wrap;margin-top:16px}.fx__status{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}.fx img{max-width:100%;display:block}.fx [hidden]{display:none!important}@media(prefers-reduced-motion:reduce){.fx *{scroll-behavior:auto!important;animation:none!important;transition:none!important}}
.pe-audit-grid{display:grid;grid-template-columns:minmax(0,1.5fr) minmax(190px,.8fr);gap:20px;align-items:start}.pe-audit-image{position:relative;overflow:hidden;border:1px solid #c4cec1;border-radius:12px;background:white}.pe-audit-image img{width:100%;aspect-ratio:2/1;object-fit:contain;filter:brightness(var(--audit-brightness,1)) contrast(var(--audit-contrast,1));transform:scale(var(--audit-zoom,1));transition:filter .12s,transform .12s}.pe-crosshair{position:absolute;inset:0;pointer-events:none;background:linear-gradient(90deg,transparent 49.9%,#203c2730 50%,transparent 50.1%),linear-gradient(0deg,transparent 49.9%,#203c2730 50%,transparent 50.1%)}.pe-audit-projects{display:grid}.pe-project{display:grid;gap:4px;text-align:left;background:transparent;border:0;border-bottom:1px solid #cfd7ca;padding:10px;cursor:pointer;color:inherit}.pe-project[aria-pressed=true]{background:#e5eadf}.pe-name{font-weight:700}.pe-sub{font-size:10px;color:#536159}.pe-audit-controls label{display:grid;gap:5px;font-size:12px;margin:12px 0}.pe-audit-controls input{width:100%;min-height:32px;accent-color:#31513f;touch-action:pan-y}.pe-audit-note{font-size:11px;color:#536159}@media(max-width:640px){.pe-audit-grid{grid-template-columns:1fr}.pe-audit-projects{grid-template-columns:repeat(3,1fr)}.pe-project{padding:8px 4px}.pe-name{font-size:14px}.pe-sub{font-size:8px}}
.fx.is-paused .pe-roll-actions .pe-name{transition:none!important;transform:none!important}.fx.is-paused .pe-magnet,.fx.is-paused .pe-magnet-label{transition:none!important;transform:none!important}
.fx.is-paused *, .fx.is-reduced-motion *{scroll-behavior:auto;animation-play-state:paused!important}
.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img,.pe-audit-image img{display:block;width:100%;height:auto;max-height:none;aspect-ratio:2/1;object-fit:contain}
@media(max-width:680px){.pe-roll-layout,.pe-mag-layout{grid-template-columns:minmax(0,1fr);gap:16px}.pe-roll-preview,.pe-mag-card,.pe-menu-image,.pe-audit-image{width:100%;min-width:0}.pe-roll-preview img,.pe-mag-image img,.pe-menu-image img,.pe-audit-image img{height:auto;aspect-ratio:2/1;object-fit:contain}.pe-roll-actions,.pe-mag-list{grid-template-columns:minmax(0,1fr)}.pe-roll-actions .pe-project,.pe-mag-list .pe-project{min-height:60px}}
.fx.is-reduced-motion .pe-name-wrap .pe-name{opacity:1!important}.fx.is-reduced-motion .pe-name-wrap .pe-marquee{display:none!important}.fx.is-reduced-motion .pe-magnet,.fx.is-reduced-motion .pe-magnet-label{transform:none!important;transition:none!important}
/* Shared visual primitives are duplicated intentionally so every effect runs alone in its iframe. */
.pe-project{box-sizing:border-box;position:relative;display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;min-width:0;min-height:60px;padding:13px 10px;border:0;border-bottom:1px solid #cfd7ca;background:transparent;color:#172523;text-align:left;font:inherit;cursor:pointer}.pe-project[aria-pressed=true]{background:#e5eadf}.pe-project:focus-visible{outline:3px solid #356940;outline-offset:-3px}.pe-name{display:block;min-width:0;font-size:clamp(16px,2vw,23px);line-height:1.2;font-weight:700;letter-spacing:-.02em}.pe-sub{display:block;min-width:0;font-size:10px;line-height:1.45;color:#536159}.pe-caption{margin:0;padding:11px 14px;font-size:10px;line-height:1.45;color:#536159}.pe-caption span{font-weight:700;color:#172523}.pe-mag-layout{display:grid;grid-template-columns:minmax(190px,.75fr) minmax(0,1.25fr);gap:22px;align-items:center}.pe-mag-list{display:grid;border-top:1px solid #cfd7ca}.pe-mag-card{min-width:0;overflow:hidden;border:1px solid #c4cec1;border-radius:12px;background:#fff}.pe-mag-image{min-width:0;overflow:hidden}.pe-mag-image img{display:block;width:100%;height:auto;aspect-ratio:2/1;object-fit:contain}.pe-menu-panel{min-width:0}.pe-menu-items{min-width:0}.pe-menu-image img,.pe-roll-preview img,.pe-audit-image img{display:block;width:100%;height:auto;aspect-ratio:2/1;object-fit:contain}@media(max-width:680px){.pe-mag-layout{grid-template-columns:minmax(0,1fr);gap:16px}.pe-mag-list{grid-template-columns:minmax(0,1fr)}.pe-mag-card{width:100%;min-width:0}.pe-project{gap:8px;padding:12px 8px}.pe-sub{font-size:10px}}
/* Phone selectors: two readable rows with names and details kept inside each tile. */
@media(max-width:680px){.pe-audit-grid{grid-template-columns:minmax(0,1fr);gap:14px}.pe-audit-projects{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;margin:0 0 12px}.pe-audit-projects .pe-project{display:grid;align-content:start;justify-items:start;gap:5px;min-width:0;min-height:68px;padding:10px;border:1px solid #cfd7ca;border-radius:8px;text-align:left}.pe-audit-projects .pe-name{font-size:15px;line-height:1.2;white-space:normal;overflow-wrap:anywhere}.pe-audit-projects .pe-sub{font-size:9px;line-height:1.35;text-align:left;white-space:normal;overflow-wrap:anywhere}.pe-audit-controls label{grid-template-columns:80px minmax(0,1fr);align-items:center;gap:10px}.pe-audit-note{margin:8px 0}}
export function mountEffect(root,{reducedMotion=false}={}){
const controller=new AbortController(), signal=controller.signal;
const buttons=[...root.querySelectorAll('[data-project]')], images=[...root.querySelectorAll('[data-preview]')];
const caption=root.querySelector('[data-caption]'), status=root.querySelector('[data-status]'), motion=root.querySelector('[data-motion]');
const toggle=root.querySelector('.pe-menu-toggle'), panel=root.querySelector('.pe-menu-panel');
const controls=[...root.querySelectorAll('button,input')];
const original={className:root.className,style:root.getAttribute('style'),buttons:buttons.map(b=>[b.className,b.getAttribute('aria-pressed')]),images:images.map(i=>[i.className,i.hidden]),caption:caption?.textContent,status:status?.textContent,auditNote:root.querySelector('[data-audit-note]')?.textContent,controls:controls.map(c=>[c,c.value,c.innerHTML,c.getAttribute('aria-expanded'),c.getAttribute('aria-pressed')]),panelHidden:panel?.hidden};
const motionReduced=!!reducedMotion||(typeof window!=='undefined'&&window.matchMedia&&window.matchMedia('(prefers-reduced-motion: reduce)').matches);
let active=0, paused=motionReduced, destroyed=false;
const cleanups=[];
const listen=(node,type,fn,opts={})=>node.addEventListener(type,fn,{...opts,signal});
const announce=s=>{if(status)status.textContent=s};
function select(index,announceChange=false){if(destroyed||!buttons[index]||!images[index])return;active=index;buttons.forEach((b,i)=>{b.setAttribute('aria-pressed',String(i===index));b.classList.toggle('is-active',i===index)});images.forEach((img,i)=>{img.hidden=i!==index;img.classList.toggle('is-active',i===index)});const projectName=buttons[index].querySelector('.pe-name')?.textContent||'';if(caption)caption.textContent=projectName;const auditNote=root.querySelector('[data-audit-note]');if(auditNote)auditNote.textContent=(root.lang.startsWith('en')?'Current view: ':'当前检查:')+(projectName)+(root.lang.startsWith('en')?' screenshot. Controls affect the preview only.':'截图。控件只改变预览显示。');if(announceChange)announce((root.lang.startsWith('en')?'Showing ':'正在显示 ')+(projectName));}
buttons.forEach((b,i)=>{listen(b,'pointerenter',e=>{if(e.pointerType==='mouse')select(i)});listen(b,'focus',()=>select(i));listen(b,'click',()=>select(i,true));listen(b,'keydown',e=>{let n;if(['ArrowDown','ArrowRight'].includes(e.key))n=(i+1)%buttons.length;else if(['ArrowUp','ArrowLeft'].includes(e.key))n=(i+buttons.length-1)%buttons.length;else if(e.key==='Home')n=0;else if(e.key==='End')n=buttons.length-1;if(n!==undefined){e.preventDefault();buttons[n].focus();select(n,true)}})});
if(motion){motion.setAttribute('aria-pressed',String(paused));motion.textContent=paused?(root.lang.startsWith('en')?'Resume motion':'继续动效'):(root.lang.startsWith('en')?'Pause motion':'暂停动效');listen(motion,'click',()=>{paused=!paused;motion.setAttribute('aria-pressed',String(paused));motion.textContent=paused?(root.lang.startsWith('en')?'Resume motion':'继续动效'):(root.lang.startsWith('en')?'Pause motion':'暂停动效');root.classList.toggle('is-paused',paused);announce(paused?(root.lang.startsWith('en')?'Motion paused':'动效已暂停'):(root.lang.startsWith('en')?'Motion resumed':'动效已继续'))})}
const audit=root.querySelector('.pe-audit-image'), note=root.querySelector('[data-audit-note]');
root.querySelectorAll('[data-filter]').forEach(input=>listen(input,'input',()=>{const key=input.dataset.filter;const value=Number(input.value);if(key==='brightness')root.style.setProperty('--audit-brightness',value/100);if(key==='contrast')root.style.setProperty('--audit-contrast',value/100);if(key==='zoom')root.style.setProperty('--audit-zoom',value/100);if(note)note.textContent=(root.lang.startsWith('en')?'Display adjustment: ':'显示调整:')+key+' '+value+'%'}));
const reset=root.querySelector('[data-reset]');if(reset)listen(reset,'click',()=>{root.querySelectorAll('[data-filter]').forEach(i=>i.value='100');root.style.setProperty('--audit-brightness','1');root.style.setProperty('--audit-contrast','1');root.style.setProperty('--audit-zoom','1');if(note)note.textContent=root.lang.startsWith('en')?'Display restored.':'已恢复初始显示。'});
cleanups.push(()=>{root.style.removeProperty('--audit-brightness');root.style.removeProperty('--audit-contrast');root.style.removeProperty('--audit-zoom')});
select(0);root.classList.toggle('is-reduced-motion',motionReduced);
return {resume(){if(destroyed)return;paused=motionReduced;root.classList.toggle('is-paused',paused);if(motion){motion.setAttribute('aria-pressed','false');motion.textContent=root.lang.startsWith('en')?'Pause motion':'暂停动效'}},pause(){if(destroyed)return;paused=true;root.classList.add('is-paused');const magnet=root.querySelector('[data-magnet]');if(magnet)magnet.style.transform='';if(motion){motion.setAttribute('aria-pressed','true');motion.textContent=root.lang.startsWith('en')?'Resume motion':'继续动效'}},destroy(){if(destroyed)return;destroyed=true;controller.abort();cleanups.forEach(fn=>fn());root.className=original.className;if(original.style===null)root.removeAttribute('style');else root.setAttribute('style',original.style);buttons.forEach((b,i)=>{b.className=original.buttons[i][0];original.buttons[i][1]===null?b.removeAttribute('aria-pressed'):b.setAttribute('aria-pressed',original.buttons[i][1])});images.forEach((img,i)=>{img.className=original.images[i][0];img.hidden=original.images[i][1]});if(caption)caption.textContent=original.caption;if(status)status.textContent=original.status;const note=root.querySelector('[data-audit-note]');if(note)note.textContent=original.auditNote;original.controls.forEach(([c,value,label,expanded,pressed])=>{if(c.matches('input'))c.value=value;if(c.matches('button'))c.innerHTML=label;expanded===null?c.removeAttribute('aria-expanded'):c.setAttribute('aria-expanded',expanded);pressed===null?c.removeAttribute('aria-pressed'):c.setAttribute('aria-pressed',pressed)});if(panel)panel.hidden=original.panelHidden}};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 页面设计复盘、案例内容检查或编辑验收;使用已有网页截图,不将截图解释为产品实拍。
交互逻辑
- 切换截图并调节三个原生滑块;CSS filter/transform 仅影响预览,恢复按钮可还原显示。
触摸与无障碍
- 无脚本时原始截图可见;减少动态时控件仍可用;触屏滑块不阻止纵向页面滚动。
本效果的接入说明
将示例图片替换为有权使用的素材,并在主题编辑器和手机上验证交互。
上线检查
接入文件
{% 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,示例独立实现。
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连续点击前先区分按钮反馈、已发请求和购物车最终数量。真实网络失败时先读现有购物车,避免因动画没播就自动再加一件。
件数从 0 到 2 再回到 0。这个样例可检验连续点击和清空后的界面反馈;接商店时还需核对真实购物车记录。
复现实验与读数
读初始件数,连续加两件,再清空演示购物车。
- 908、316 px,两种偏好
- 0,再到 2,再到 0
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Add to demo cart | 原为“Demo cart is empty.”。操作后显示“1 item added.”。 |
| 1440 / 908 px | Add to demo cart | 原为“Demo cart is empty.”。操作后显示“1 item added.”。 |
正在准备预览
特效说明
先确认成功,再播动效
在预览里点一次加购,留意右上角数量。正式接入时,要等接口确认才给成功提示,库存或网络错误应显示在加购按钮旁。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx cart" lang="en" aria-label="Add to cart feedback demo">
<header class="cart-header"><h2>Add to cart feedback</h2><span class="count">Cart <strong data-count>0</strong></span></header>
<figure class="product"><img src="https://www.weswoo.com/wp-content/themes/weswoo/assets/images/case-brands/project-previews/shokz-openfit-preview.webp" alt="Shokz UK storefront screenshot"></figure>
<div class="cart-actions"><button class="buy" type="button" data-add>Add to demo cart</button>
<button class="reset" type="button" data-reset>Clear cart</button></div>
<p class="cart-status" role="status" data-status>Demo cart is empty.</p>
</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; }
.cart { position: relative; isolation: isolate; overflow: hidden; }
.cart-header, .cart-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.count { display: inline-flex; align-items: center; gap: 8px; padding: 7px 13px; border: 1px solid #84968a; border-radius: 100px; }
.count strong { display: grid; place-items: center; min-width: 1.7em; aspect-ratio: 1; color: #18211e; background: #e0fa93; border-radius: 50%; }
.product { margin-block: 18px; border-radius: 12px; overflow: hidden; background: #48564d; }
.product img { aspect-ratio: 2 / 1; object-fit: cover; object-position: 50% 25%; }
.cart-actions { justify-content: flex-start; }
.buy, .reset { border-radius: 7px; padding: 8px 14px; border: 1px solid #84968a; }
.buy { color: #18211e; background: #e0fa93; font-weight: 650; }
.reset { color: inherit; background: transparent; }
.cart-status { min-height: 1.6em; margin-top: 10px; color: #d3ded4; }
.cart-trail { position: absolute; z-index: 1; width: 66px; aspect-ratio: 1; object-fit: cover; border-radius: 8px; pointer-events: none; }/*
MIT License
Copyright (c) 2024 Andrea Biason
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.
*/
// Adapted from Andrea Biason's product-to-cart coordinate transition for Codrops.
export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const add = root.querySelector('[data-add]');
const reset = root.querySelector('[data-reset]');
const counter = root.querySelector('[data-count]');
const status = root.querySelector('[data-status]');
const image = root.querySelector('.product img');
let quantity = 0;
let motion = false;
let trail;
let animation;
function stopTrail() {
animation?.cancel();
trail?.remove();
animation = trail = undefined;
}
function show(quantity, message) {
counter.textContent = quantity;
status.textContent = message;
}
add.addEventListener('click', () => {
show(++quantity, quantity === 1 ? '1 item added.' : quantity + ' items in the demo cart.');
stopTrail();
if (!motion || !image.naturalWidth || !Element.prototype.animate) return;
const from = image.getBoundingClientRect();
const to = counter.getBoundingClientRect();
const canvas = root.getBoundingClientRect();
const x = from.left + from.width / 2 - 33;
const y = from.top + from.height / 2 - 33;
trail = image.cloneNode();
trail.alt = '';
trail.setAttribute('aria-hidden', 'true');
trail.className = 'cart-trail';
trail.style.left = x - canvas.left + 'px';
trail.style.top = y - canvas.top + 'px';
root.append(trail);
const dx = to.left + to.width / 2 - x - 33;
const dy = to.top + to.height / 2 - y - 33;
animation = trail.animate([
{transform:'translate(0, 0) scale(1)', opacity:1},
{transform:'translate(' + dx + 'px, ' + dy + 'px) scale(.2)', opacity:.2}
], {duration:540, easing:'cubic-bezier(.18,.7,.2,1)'});
animation.onfinish = stopTrail;
}, {signal:lifetime.signal});
reset.addEventListener('click', () => {
quantity = 0;
stopTrail();
show(quantity, 'Demo cart cleared.');
}, {signal:lifetime.signal});
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; stopTrail(); },
destroy() { lifetime.abort(); stopTrail(); }
};
}接入与验收
接入主题
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 原版演示动效思路改编自 Andrea Biason 为 Codrops 发布的 MIT 示例。演示使用 WESWOO 的 Shokz 英国站案例画面。
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先搜 A 再立即改成 B,让 A 的结果最后才到。最终建议、计数和选择目标都应属于 B;静态过滤演示不能证明真实预测接口已处理过期响应。
第二次查询清掉了第一次的两个匹配项。零结果也值得验,它能暴露旧建议仍残留在框里的问题。
复现实验与读数
打开样例搜索,输入 shirt,再输入 zzz,读取结果数。
- 908、316 px,两种偏好
- 2 results,再到 0 results
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Search products | 操作后显示“4 results”。 |
| 1440 / 908 px | Search products | 操作后显示“4 results”。 |
正在准备预览
特效说明
先让顾客可以输入
试着搜索 shirt,再换成一个没有匹配的词。结果数量应与列表一致,顾客仍可改词或关闭。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx search-demo" lang="en" aria-label="Product search preview">
<div class="search-cover">
<img src="__WW_VISUAL_1__" alt="">
<div class="cover-copy">
<h2>Find what fits</h2>
<button type="button" data-search-open aria-expanded="false" aria-controls="search-panel">Search products</button>
</div>
</div>
<section id="search-panel" aria-label="Product search" hidden>
<div class="search-field">
<label for="sample-query">Search the sample catalog</label>
<button type="button" data-search-close>Close</button>
<input type="search" id="sample-query" autocomplete="off" placeholder="Try shirt, bag or shoe" aria-controls="sample-results">
</div>
<p class="search-count" role="status">4 results</p>
<ul id="sample-results">
<li>Oxford shirt <span>Clothing</span></li>
<li>Linen shirt <span>Clothing</span></li>
<li>Canvas tote bag <span>Accessories</span></li>
<li>Trail shoes <span>Footwear</span></li>
</ul>
<p class="no-results" hidden>Try a shorter search term.</p>
</section>
</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; }
.search-demo { --paper: #f1efeb; }
.search-cover { position: relative; display: grid; align-items: end; min-height: clamp(235px,42vw,420px); overflow: hidden;
isolation: isolate; border-radius: 12px; background: #304543; color: #fff; }
.search-cover img,.search-cover::after { position: absolute; inset: 0; width: 100%; height: 100%; }
.search-cover img { object-fit: cover; object-position: 50% 45%; z-index: -2; }
.search-cover::after { content: ""; z-index: -1; background: linear-gradient(0deg, #121d1dee, #121d1d33 80%); }
.cover-copy { padding: clamp(18px,5vw,44px); }
.cover-copy h2 { margin-bottom: 16px; }
[data-search-open] { background: #fbf7ea; border: 1px solid transparent; color: #233b36; font-weight: 650; }
#search-panel { color: #233b36; border: 1px solid var(--edge); padding: clamp(10px,3vw,24px); border-radius: 12px; background: #fffdf5; }
.search-field { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 8px; align-items: center; }
.search-field label { font-weight: 650; }
.search-field button { background: transparent; color: inherit; border: 1px solid var(--edge); }
.search-field input { grid-column: 1 / -1; width: 100%; min-width: 0; min-height: 44px; background: #ecf0e8;
color: #233b36; border: 1px solid #81968d; border-radius: 8px; padding: 9px 12px; }
.search-count { margin-block: 12px 6px; color: #52685d; }
#sample-results { list-style: none; padding: 0; margin: 0; }
#sample-results li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; padding: 8px 0; border-top: 1px solid var(--edge); }
#sample-results span { color: #52685d; font-size: .85rem; }// Adapted from Codrops' MorphingSearch focus, explicit close and Escape pattern.
// Source: https://github.com/codrops/MorphingSearch (Codrops, 2014).
export function mountEffect(root, {reducedMotion = matchMedia('(prefers-reduced-motion: reduce)').matches} = {}) {
const lifetime = new AbortController();
const options = {signal:lifetime.signal};
const cover = root.querySelector('.search-cover');
const trigger = root.querySelector('[data-search-open]');
const panel = root.querySelector('#search-panel');
const query = root.querySelector('#sample-query');
const rows = [...root.querySelectorAll('#sample-results li')];
const count = root.querySelector('.search-count');
const empty = root.querySelector('.no-results');
let motion = false;
let animation;
function updateResults() {
const words = query.value.trim().toLowerCase().split(/\s+/).filter(Boolean);
let matches = 0;
for (const row of rows) {
const text = row.textContent.toLowerCase();
row.hidden = !words.every(word => text.includes(word));
if (!row.hidden) matches++;
}
count.textContent = matches === 1 ? '1 result' : matches + ' results';
empty.hidden = matches > 0;
}
function setOpen(open) {
animation?.cancel();
const oldWidth = trigger.getBoundingClientRect().width;
trigger.setAttribute('aria-expanded', String(open));
panel.hidden = !open;
cover.hidden = open;
if (open) {
query.focus({preventScroll:true});
if (motion && Element.prototype.animate) {
const newWidth = panel.getBoundingClientRect().width;
animation = panel.animate([
{clipPath:'inset(0 ' + Math.max(0, newWidth - oldWidth) + 'px 0 0 round 8px)', opacity:.65},
{clipPath:'inset(0 0 0 0 round 8px)', opacity:1}
], {duration:240,easing:'ease-out'});
}
} else {
trigger.focus({preventScroll:true});
}
}
trigger.addEventListener('click', () => setOpen(true), options);
root.querySelector('[data-search-close]').addEventListener('click', () => setOpen(false), options);
query.addEventListener('input', updateResults, options);
root.addEventListener('keydown', event => {
if (event.key === 'Escape' && !panel.hidden) {
event.preventDefault();
setOpen(false);
}
}, options);
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; animation?.cancel(); },
destroy() { lifetime.abort(); animation?.cancel(); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 店铺顶部搜索入口,或类目中的商品搜索。
交互逻辑
- 展开后将焦点放到输入框,查询变化时更新结果和数量。关闭后焦点回到原入口。
触摸与无障碍
- 手机可点按关闭,键盘可用 Esc。减少动态时搜索区域直接展开。
本效果的接入说明
接入 Shopify 预测搜索时,仅呈现最新查询的响应,并给加载、无结果和失败分别提供提示。
上线检查
接入文件
{% 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 MorphingSearch。封面沿用原版演示中注明来自 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从一个分支钻到末级再逐级返回,然后进入同名的第二个分支。核对每一级的标题、焦点和返回目标;浏览器后退是否退出菜单要在真实站点单独验。
进到 Shirts 和 Outerwear 后,返回恢复 Clothing 和 Accessories。由此可以检查返回恢复的是父级而非一张空列表。
复现实验与读数
进入 Clothing 再返回,读取每一步能选的栏目。
- 908、316 px,两种偏好
- Clothing / Accessories,再到 Shirts / Outerwear,再到 Clothing / Accessories
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Clothing | 从 Clothing 进入后,看到了 Shirts 和 Outerwear 两个下级入口,以及返回上一级的 Back。 |
| 1440 / 908 px | Clothing | 从 Clothing 进入后,看到了 Shirts 和 Outerwear 两个下级入口,以及返回上一级的 Back。 |
正在准备预览
特效说明
把分类路径做清楚
点 Clothing,再点 Shirts。返回时保留之前的部门位置,顾客无需从头浏览。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx drill" lang="en" aria-label="Collection drilldown demo">
<div class="cols">
<div>
<h2>Browse the store</h2>
<p class="intro">Choose a department to see its collections.</p>
<div class="panel">
<div class="row drill-head"><h3 tabindex="-1">Departments</h3><button type="button" data-back hidden>Back</button></div>
<div class="drill-options">
<button type="button" data-branch="Clothing">Clothing</button>
<button type="button" data-branch="Accessories">Accessories</button>
</div>
<p class="status" role="status" data-choice></p>
</div>
</div>
<figure><img src="__WW_VISUAL_1__" alt="Blue tailored outfit from the Codrops ColumnScroll demo"></figure>
</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); } }
.drill { --paper:#e6ecee; --accent:#1b5270; }
.drill-head { justify-content:space-between; }
.drill-options { display:grid; gap:7px; margin-top:10px; }
.drill-options button { text-align:left; }
.drill figure img { width:100%; height:clamp(138px,28vw,345px); object-fit:cover; object-position:50% 30%; border-radius:12px; }
@media(max-width:600px){ .drill figure img { height:116px; } }/*
* Adapted from Multi-Level Menu; Copyright (c) 2015 Codrops.
* https://github.com/codrops/MultiLevelMenu/blob/master/js/main.js
* The original JavaScript is licensed under the MIT License.
*
* 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 $ = 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 menu = $('.drill-options');
const heading = $('.drill-head h3');
const back = $('[data-back]');
const status = $('[data-choice]');
const departments = ['Clothing','Accessories'];
const tree = {Clothing:['Shirts','Outerwear'],Accessories:['Bags','Caps']};
function show(department) {
const previous = heading.textContent;
heading.textContent = department || 'Departments';
back.hidden = !department;
status.textContent = '';
const entries = department ? tree[department] : departments;
menu.replaceChildren(...entries.map(label => {
const button = document.createElement('button');
button.type = 'button';
button.textContent = label;
button.dataset[department ? 'leaf' : 'branch'] = label;
return button;
}));
reveal(menu, department ? 'translateX(9px)' : 'translateX(-9px)');
const returnControl = all('[data-branch]').find(button => button.dataset.branch === previous);
(returnControl || heading).focus({preventScroll:true});
}
listen(menu,'click',event => {
const control = event.target.closest('button');
if (!control) return;
if (control.dataset.branch) {
show(control.dataset.branch);
return;
}
status.textContent = 'Collection selected: ' + control.dataset.leaf;
reveal(status);
});
listen(back,'click',() => show(null));
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 Multi-Level Menu 的 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尺寸按钮上方能直接切英寸吗?我不想再放一张尺码表。
可以。切换单位时只改选项的显示文字,保留提交的变体 ID。样例里的 25.4 cm 与 25.49 cm 都会四舍五入成 10.0 in,因此又显示原厘米数,顾客仍能分清,之前选的 702 也没变。
将单位选择器放在真实尺寸选择器旁。原始厘米数保存在 data-cm;每次从它换算,提交值仍是商品变体 ID。遇到英寸舍入重名,显示原厘米数或增加有意义的精度。
查看对照结果、适用条件与复测代码
两款只按一位小数显示时只有一个独特英寸标记;修正后两款各有可区分的文字。
切回厘米保留 25.49 的原始精度;浏览器提交的变体仍为 702。
这段测试是独立的行内选择器,和本页原有的弹窗尺码表使用场景不同。实际集成要保留主题已有的变体选中、库存和购买表单联动。
function setSizeUnit(select, unit) {
const labels = Array.from(select.options, option => {
const raw=option.dataset.cm;
return raw?.trim() && Number.isFinite(Number(raw)) ? (Number(raw)/2.54).toFixed(1) : null;
});
for (const [index, option] of Array.from(select.options).entries()) {
const label = labels[index];
if (label == null) continue;
const ambiguous = labels.indexOf(label) !== labels.lastIndexOf(label);
option.textContent = unit === 'in'
? label+' in'+(ambiguous ? ' ('+option.dataset.cm+' cm)' : '')
: option.dataset.cm+' cm';
}
// Preserve each option's value (the variant ID) and the current selection.
}
// Example: units is the unit selector and sizes is the variant selector.
units.addEventListener('change', () => setSizeUnit(sizes, units.value)); WESWOO 实测于 157.0.8103.79 版 Chrome。在空目录中使用 Node.js 22 或更新版本,依次运行 npm install playwright、npx playwright install chromium,再运行 node weswoo-measurements.cjs。
提问原帖 · Shopify · Support product variants · MDN · HTMLSelectElement.value
切厘米到英寸再切回时,用同一份原始测量值重新计算。若反复切换后数值漂移,查是否拿已四舍五入的显示字符串作下一次输入;量的是衣长还是胸围也要写清。
48 cm 换算后显示 18.9 in,再切回仍为 48 cm。往返检验可发现拿显示过的约数继续换算造成的漂移。
复现实验与读数
对同一件 S 码衣服依次选择厘米、英寸、厘米,读取宽度。
- 908、316 px,两种偏好
- 48 (cm),再到 18.9 (in),再到 48 (cm)
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Open size guide | 打开尺码表后,默认单位是厘米。S 码的宽和长分别为 48 厘米和 66 厘米。 |
| 1440 / 908 px | Open size guide | 打开尺码表后,默认单位是厘米。S 码的宽和长分别为 48 厘米和 66 厘米。 |
正在准备预览
特效说明
从同一份尺码数据出发
切成英寸再切回厘米,原数据会保持一致。表头应明确是成衣尺寸还是人体尺寸。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx size-guide" lang="en" aria-label="Size guide demo">
<div class="cols">
<div>
<h2>Find your size</h2>
<p class="intro">Compare the sample garment measurements before choosing.</p>
<button type="button" class="primary" data-size-open>Open size guide</button>
</div>
<img class="product-photo" src="__WW_VISUAL_1__" alt="Sage graphic T-shirt">
</div>
<dialog aria-labelledby="size-title">
<div class="row guide-head"><h3 id="size-title">Garment measurements</h3><button type="button" data-close>Close</button></div>
<div class="row" role="group" aria-label="Measurement units">
<button type="button" data-unit="cm" aria-pressed="true">cm</button>
<button type="button" data-unit="in" aria-pressed="false">in</button>
</div>
<table><caption>Sample chart <span data-unit-label>(cm)</span></caption>
<thead><tr><th scope="col">Size</th><th scope="col">Width</th><th scope="col">Length</th></tr></thead>
<tbody><tr><th scope="row">S</th><td data-cm="48">48</td><td data-cm="66">66</td></tr>
<tr><th scope="row">M</th><td data-cm="51">51</td><td data-cm="69">69</td></tr>
<tr><th scope="row">L</th><td data-cm="54">54</td><td data-cm="72">72</td></tr></tbody>
</table>
<p class="status" role="status" data-units-status>Showing centimeters.</p>
</dialog>
</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); } }
.size-guide { --paper:#e9eee1; min-height:360px; }
.size-guide dialog { max-width:min(480px,calc(100% - 24px)); max-height:calc(100% - 24px);
width:100%; color:var(--ink); border:1px solid var(--edge); border-radius:12px; padding:12px; background:var(--card); }
.size-guide dialog::backdrop { background:#18352788; }
.guide-head { justify-content:space-between; margin-bottom:10px; }
.size-guide table { border-collapse:collapse; table-layout:fixed; width:100%; margin-top:9px; }
.size-guide caption { text-align:left; color:var(--mute); }
.size-guide th,.size-guide td { padding:5px 4px; border-bottom:1px solid var(--edge); text-align:left; }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 trigger = $('[data-size-open]');
const dialog = $('dialog');
const units = all('[data-unit]');
listen(trigger,'click',() => {
dialog.showModal();
reveal(dialog);
});
listen($('[data-close]'),'click',() => dialog.close());
listen(dialog,'close',() => trigger.focus({preventScroll:true}));
for (const button of units) listen(button,'click',() => {
const inches = button.dataset.unit === 'in';
for (const cell of all('[data-cm]')) {
cell.textContent = inches ? (Number(cell.dataset.cm)/2.54).toFixed(1) : cell.dataset.cm;
}
for (const unit of units) unit.setAttribute('aria-pressed',String(unit===button));
$('[data-unit-label]').textContent = inches ? '(in)' : '(cm)';
$('[data-units-status]').textContent = inches ? 'Showing inches.' : 'Showing centimeters.';
reveal($('tbody'));
});
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; cancelMotion(); },
destroy() { lifetime.abort(); cancelMotion(); if (dialog.open) dialog.close(); }
};
}接入与验收
接入主题
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 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把数量改到上限,再试减少和手工输入。按最终接受的数量核对小计;真实购物车若有量价阶梯、折扣和库存限制,应读取服务端返回值。
库存上限为三件,重复按加号停在 $78。减一件回到 $52,说明小计也跟随上限后的有效数量。
复现实验与读数
初始一件,连续按加号四次,再减一件,记录“数量 / 小计”。
- 908、316 px,两种偏好
- 1 / $26.00,再到 3 / $78.00,再到 2 / $52.00
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Increase quantity | 单件示例价为 $26。数量从 1 加到 2,小计从 $26.00 变成 $52.00;可用数量提示为 2 of 3。 |
| 1440 / 908 px | Increase quantity | 单件示例价为 $26。数量从 1 加到 2,小计从 $26.00 变成 $52.00;可用数量提示为 2 of 3。 |
正在准备预览
特效说明
把数量和小计放在一起
尝试加到三件再增加。达到上限后应给清楚反馈,购买金额仍对应当前数量。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx quantity-demo" lang="en" aria-label="Cart quantity demo">
<div class="cols">
<img class="product-photo" src="__WW_VISUAL_1__" alt="Rose graphic T-shirt">
<div>
<h2>Adjust quantity</h2>
<p class="intro">Rose tee · sample price $26 each</p>
<div class="panel">
<div class="row quantity-stepper" role="group" aria-label="Quantity">
<button type="button" data-step="-1" aria-label="Decrease quantity" aria-disabled="true">−</button>
<output data-qty>1</output>
<button type="button" data-step="1" aria-label="Increase quantity" aria-disabled="false">+</button>
</div>
<p class="qty-total">Subtotal <strong data-total>$26.00</strong></p>
<p class="status" role="status" data-cap>1 of 3 available</p>
</div>
</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); } }
.quantity-demo { --paper:#f5ebe9; --accent:#713e4f; }
.quantity-demo .product-photo { background:#ecdbdd; }
.quantity-stepper output { min-width:24px; text-align:center; font-variant-numeric:tabular-nums; }
.quantity-stepper button { min-width:44px; font-size:1.2rem; }
.quantity-stepper [aria-disabled="true"] { opacity:.55; cursor:default; }
.qty-total { display:flex; flex-wrap:wrap; justify-content:space-between; gap:8px; margin-top:12px; font-variant-numeric:tabular-nums; }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 controls = all('[data-step]');
const format = new Intl.NumberFormat('en-US',{style:'currency',currency:'USD'});
let quantity = 1;
const max = 3;
for (const button of controls) listen(button,'click',() => {
const next = quantity + Number(button.dataset.step);
if (next < 1 || next > max) return;
quantity = next;
$('[data-qty]').value = quantity;
$('[data-total]').textContent = format.format(quantity * 26);
$('[data-cap]').textContent = quantity === max ? 'Maximum available quantity: 3.' : quantity + ' of 3 available';
for (const control of controls) {
control.setAttribute('aria-disabled',String(control.dataset.step === '1' ? quantity===max : quantity===1));
}
reveal($('[data-total]'));
});
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 的开源购物车。商品图来自 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只用键盘删除最后一件,再按 Enter 撤销,核对回到哪一行和哪个控件。演示会恢复本地行;真实购物车另查该变体、刻字、订阅方案和价格是否仍可恢复。
移除后小计归零,撤销后同一个 Sky tee 和 $24 同时恢复。只看列表重新出现,容易漏掉金额没有恢复的情况。
复现实验与读数
记录一行商品的金额,移除最后一件,然后撤销。
- 908、316 px,两种偏好
- 1 item · $24.00,再到 Sky tee removed · $0.00,再到 Sky tee restored · $24.00
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Remove item | 原为“1 item · $24.00”。操作后显示“Sky tee removed · $0.00”。 |
| 1440 / 908 px | Remove item | 原为“1 item · $24.00”。操作后显示“Sky tee removed · $0.00”。 |
查看 WESWOO 的实测步骤和结果
从带一件商品的预览开始,用键盘聚焦 Remove item,然后连续按两次 Enter。每次先找焦点,再读合计。
| 键盘操作 | 金额 / 下一处焦点 |
|---|---|
| 在 Remove item 上按 Enter | $0.00 / Undo removal |
| 在 Undo removal 上按 Enter | $24.00 / Remove item |
实测用了减少动态效果偏好。实际购物车还要确认服务器已恢复商品行、数量和价格;这个预览只演示反馈和焦点。
正在准备预览
特效说明
已验证的结果
键盘删掉唯一一件商品后,下一步按什么?我们删掉 24 美元的 Sky tee,焦点落到了 Undo removal。再按一次 Enter,商品回来,焦点也回到了 Remove item。
让误删有一条短路可走
点 Remove item,再点 Undo removal。商品、金额和操作焦点会一起恢复。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx undo-demo" lang="en" aria-label="Cart removal and undo demo">
<h2>Your demo cart</h2>
<div class="panel cart-line">
<img class="product-photo" src="__WW_VISUAL_1__" alt="Sky blue graphic T-shirt">
<div><h3>Sky tee</h3><p>$24.00</p><button type="button" data-remove>Remove item</button></div>
</div>
<div class="panel empty-cart" hidden><h3>Your cart is empty</h3><p>Restore the last item if you removed it by mistake.</p></div>
<div class="row undo-row"><p class="status" role="status" data-state>1 item · $24.00</p><button type="button" data-undo hidden>Undo removal</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); } }
.undo-demo { --paper:#e8eff4; --accent:#28556f; }
.cart-line { display:grid; grid-template-columns:minmax(74px,.7fr) minmax(0,1fr); align-items:center; gap:12px; margin-top:14px; }
.cart-line p { margin:3px 0 7px; }
.cart-line img { background:#deebef; height:clamp(80px,17vw,145px); }
.empty-cart { margin-top:14px; }
.undo-row { margin-top:9px; align-items:center; justify-content:space-between; }
.undo-row .status { margin-top:0; }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 line = $('.cart-line');
const empty = $('.empty-cart');
const remove = $('[data-remove]');
const undo = $('[data-undo]');
const status = $('[data-state]');
function setRemoved(removed) {
line.hidden = removed;
empty.hidden = undo.hidden = !removed;
status.textContent = removed ? 'Sky tee removed · $0.00' : 'Sky tee restored · $24.00';
(removed ? undo : remove).focus({preventScroll:true});
reveal(removed ? empty : line);
}
listen(remove,'click',() => setRemoved(true));
listen(undo,'click',() => setRemoved(false));
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 Notification Styles。商品图来自 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保持购物车不变,只改邮编,再选快递或自提。演示中的费用用于检查旧费率会不会残留;实际可选服务及收费必须用这个地址重新报价。
这个演示从 $6 切到 $14,再切到免费自提。自提覆盖了上一项加急费,可用来验费用是否残留。
复现实验与读数
依次选标准、加急和自提,逐项读取“已选方式 / 费用”。
- 908、316 px,两种偏好
- Standard / $6.00,再到 Express / $14.00,再到 Store pickup / Free
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Express | 原为“Standard $6.00 3–5 business days”。操作后显示“Express $14.00 1–2 business days”。 |
| 1440 / 908 px | Express | 原为“Standard $6.00 3–5 business days”。操作后显示“Express $14.00 1–2 business days”。 |
正在准备预览
特效说明
价格和时效一起更新
切到 Express 或 Store pickup,费用和时效应一起变化,避免顾客只看到新价格却误读旧时效。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx delivery-demo" lang="en" aria-label="Delivery options demo">
<h2>Choose delivery</h2>
<p class="intro">Sample rates and estimates</p>
<div class="cols">
<fieldset class="panel delivery-options"><legend>Delivery method</legend>
<label><input type="radio" name="delivery" value="standard" checked><span>Standard</span></label>
<label><input type="radio" name="delivery" value="express"><span>Express</span></label>
<label><input type="radio" name="delivery" value="pickup"><span>Store pickup</span></label>
</fieldset>
<div class="panel delivery-summary" role="status" aria-atomic="true">
<h3 data-method>Standard</h3>
<p data-fee>$6.00</p>
<p data-estimate>3–5 business days</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); } }
.delivery-demo { --paper:#ecf0e7; --accent:#3e5c38; }
.delivery-options { min-width:0; }
.delivery-options legend { font-weight:650; padding-inline:5px; }
.delivery-options label { display:flex; gap:9px; align-items:center; cursor:pointer; min-height:44px; padding:6px; }
.delivery-options input { accent-color:var(--accent); width:17px; height:17px; }
.delivery-summary { background:#dce7d5; }
.delivery-summary [data-fee] { font-size:1.45rem; font-weight:650; margin:6px 0; font-variant-numeric:tabular-nums; }
.delivery-summary [data-estimate] { color:var(--mute); }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 rates = {
standard:['Standard','$6.00','3–5 business days'],
express:['Express','$14.00','1–2 business days'],
pickup:['Store pickup','Free','Ready next business day']
};
for (const input of all('input[name=delivery]')) listen(input,'change',() => {
if (!input.checked) return;
const [method,fee,estimate] = rates[input.value];
$('[data-method]').textContent = method;
$('[data-fee]').textContent = fee;
$('[data-estimate]').textContent = estimate;
reveal($('.delivery-summary'));
});
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 的选项设计,演示费率和时效为样本。
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,再到 2,再到 1 / test@example.com
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | Continue | 填写示例邮箱并继续后,界面从 Contact 切到 Destination,出现邮编输入和返回按钮。 |
| 1440 / 908 px | Continue | 填写示例邮箱并继续后,界面从 Contact 切到 Destination,出现邮编输入和返回按钮。 |
正在准备预览
特效说明
先确认每一步,再让人继续
输入示例邮件和邮编,进入汇总后点 Back 改一次。填写过的内容应该保留。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx checkout-demo" lang="en" aria-label="Checkout step demo">
<h2>Checkout walkthrough</h2>
<p class="intro">Use sample details to try the steps.</p>
<ol class="checkout-steps" aria-label="Checkout steps">
<li aria-current="step">Contact</li><li>Destination</li><li>Review</li>
</ol>
<form class="panel" novalidate autocomplete="off">
<div data-step-panel>
<h3 tabindex="-1">Contact</h3><label for="sample-email">Email</label>
<input id="sample-email" type="email" placeholder="demo@example.com" required>
</div>
<div data-step-panel hidden>
<h3 tabindex="-1">Destination</h3><label for="sample-postal">Postal code</label>
<input id="sample-postal" type="text" placeholder="12345" required>
</div>
<div data-step-panel hidden>
<h3 tabindex="-1">Review sample details</h3>
<dl><dt>Email</dt><dd data-email></dd><dt>Postal code</dt><dd data-postal></dd></dl>
</div>
<div class="row step-actions"><button type="button" data-previous hidden>Back</button><button type="button" class="primary" data-next>Continue</button></div>
</form>
<p class="panel checkout-complete" tabindex="-1" role="status" hidden>Walkthrough complete.</p>
</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); } }
.checkout-demo { --paper:#ebeaf2; --accent:#4e4977; }
.checkout-steps { display:flex; flex-wrap:wrap; gap:7px; padding:0; list-style:none; margin-bottom:10px; }
.checkout-steps li { flex:1 1 auto; padding:6px 7px; border:1px solid var(--edge); border-radius:6px; color:var(--mute); }
.checkout-steps [aria-current=step] { color:white; background:var(--accent); border-color:var(--accent); font-weight:650; }
.checkout-demo form label { display:block; margin:8px 0 4px; }
.checkout-demo form input { width:100%; max-width:29rem; min-height:44px; padding:7px;
border:1px solid #7e7994; background:#fff; border-radius:7px; }
.checkout-demo dt { margin-top:6px; font-weight:650; }
.checkout-demo dd { overflow-wrap:anywhere; }
.step-actions { margin-top:11px; }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 form = $('form');
const panels = all('[data-step-panel]');
const markers = all('.checkout-steps li');
const back = $('[data-previous]');
const next = $('[data-next]');
let step = 0;
function go(index) {
step = index;
panels.forEach((panel,i) => { panel.hidden = i !== step; });
markers.forEach((marker,i) => {
if (i === step) marker.setAttribute('aria-current','step');
else marker.removeAttribute('aria-current');
});
back.hidden = step === 0;
next.textContent = step === 2 ? 'Finish walkthrough' : 'Continue';
if (step === 2) {
$('[data-email]').textContent = $('#sample-email').value;
$('[data-postal]').textContent = $('#sample-postal').value.trim();
}
panels[step].querySelector('h3').focus({preventScroll:true});
reveal(panels[step]);
}
function advance() {
const field = panels[step].querySelector('input');
if (field && !field.reportValidity()) return;
if (step < 2) {
go(step + 1);
return;
}
form.hidden = true;
$('.checkout-complete').hidden = false;
$('.checkout-complete').focus({preventScroll:true});
reveal($('.checkout-complete'));
}
listen(back,'click',() => go(step - 1));
listen(next,'click',advance);
listen(form,'keydown',event => {
if (event.key !== 'Enter' || event.isComposing || event.target.tagName !== 'INPUT') return;
event.preventDefault();
advance();
});
listen(form,'submit',event => event.preventDefault());
return {
resume() { motion = !reducedMotion; },
pause() { motion = false; cancelMotion(); },
destroy() { lifetime.abort(); cancelMotion(); }
};
}接入与验收
接入主题
3 步复制要接入的主题
在主题副本里接入和预览示例。
把素材接到区块设置
将示例文字与图片替换为 Section 设置,并把样式限定在当前 Section。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 地址表单、询价向导和结账流程原型。
交互逻辑
- 当前步骤先校验,再进入下一步,返回时保留已填值。
触摸与无障碍
- 支持键盘提交,步骤变化后焦点落到新标题。
本效果的接入说明
真实 Shopify 结账仍由平台承接,这段代码可用于主题里的询价或预结账向导。
上线检查
接入文件
{% 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 Fullscreen Form Interface。示例输入只用于当前预览状态。
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切换尺码后,记录可取货门店、所选地点和最终提交的变体。原门店突然不能取时应允许重新选择,不能保留已失效的领取承诺。
North Studio 和 Market Street 的可提货状态随尺码对调。只验一家门店会错过另一行仍停在旧规格的问题。
复现实验与读数
先读默认尺码的两个门店,再切到 M 比较同两家店。
- 908、316 px,两种偏好
- North Studio Ready in 2 hours Market Street Unavailable,再到 North Studio Unavailable Market Street Ready tomorrow
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | M | 原为“North Studio Ready in 2 hours Market Street Unavailable”。操作后显示“North Studio Unavailable Market Street Ready tomorrow”。 |
| 1440 / 908 px | M | 原为“North Studio Ready in 2 hours Market Street Unavailable”。操作后显示“North Studio Unavailable Market Street Ready tomorrow”。 |
正在准备预览
特效说明
同款不一定在同一家店有货
去门店之前,买家关心的是选中的那件。把门店和备货时间放在一起,切换尺码后两行都要更新。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx pickup" lang="en" aria-label="Pickup by size">
<div class="tee" data-stage><img src="__WW_VISUAL_1__" alt="Pale blue everyday tee"></div>
<div><p class="eyebrow">STUDIO BASICS</p><h2>Everyday tee</h2>
<fieldset><legend>Choose a size</legend><div class="row"><button aria-pressed="true" data-size="S">S</button><button aria-pressed="false" data-size="M">M</button><button aria-pressed="false" data-size="L">L</button></div></fieldset>
<h3>Store pickup</h3><div data-stores role="status"></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); } }
.pickup{display:grid;grid-template-columns:minmax(0,.8fr) minmax(0,1.2fr);gap:clamp(16px,3vw,34px);align-items:center;background:#eef1f3;color:#192e3e}
.tee{background:#fff;border-radius:8px}.tee img{width:100%;height:clamp(130px,24vw,235px);object-fit:contain}
.pickup fieldset{padding:0;margin:12px 0;border:0}.pickup legend{margin-bottom:6px}.pickup button{min-width:44px}.pickup h3{margin:12px 0 5px}
.pickup [data-stores] p{display:flex;justify-content:space-between;gap:5px;flex-wrap:wrap;border-top:1px solid #c2cdd0;padding:6px 0;font-size:14px}
@media(max-width:520px){.pickup{grid-template-columns:1fr;gap:14px}.tee img{height:115px}}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 inventory = {S:['Ready in 2 hours','Unavailable'],M:['Unavailable','Ready tomorrow'],L:['Unavailable','Unavailable']};
function show(size) {
all('[data-size]').forEach(button=>button.setAttribute('aria-pressed',String(button.dataset.size===size)));
const panel=$('[data-stores]');
const rows=inventory[size].map((value,i)=>{
const row=document.createElement('p'), name=document.createElement('b'), status=document.createElement('span');
name.textContent=['North Studio','Market Street'][i]; status.textContent=value;
row.append(name,status); return row;
});
panel.replaceChildren(...rows); reveal(panel);
}
all('[data-size]').forEach(button=>listen(button,'click',()=>show(button.dataset.size)));
show('S');
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。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 尺码选择器附近。
交互逻辑
- 各门店根据当前变体更新可取状态。
触摸与无障碍
- 点按或用键盘选择尺码,门店名称始终可见。
本效果的接入说明
使用当前变体的 store_availabilities。只对支持自提且可取的地点显示备货时间。
上线检查
接入文件
{% 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 的变体自提数据结构。实物图取自 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输入坏码后分别看旧优惠、当前小计和错误提示,再明确点移除。本地示例能区分拒绝新码与撤销旧码;组合、到期和结账资格要核对真实折扣分摊。
正确码把小计降到 $72;再交一个无效码,仍是 $72。主动移除才回 $80。这个样例能把“新码失败”和“原优惠被撤回”分开。
复现实验与读数
从 $80 开始,依次输入 STUDIO10、无效码 INVALID,最后主动移除。
- 908、316 px,两种偏好
- $80.00,再到 $72.00,再到 $72.00,再到 $80.00
WESWOO 在独立 Chrome 窗口载入本页公开示例的 HTML、CSS 和 JavaScript,预览高 700 px。两种宽度下都单独测试默认偏好和减少动态效果。
2026-11-24 · Chrome 157.0.8103.79
查看手机与桌面的演示记录
WESWOO · 2026-11-24。手机宽度开启了减少动态效果,桌面宽度使用默认动态设置。下表记录本站正式演示中的界面。
| 窗口 / 预览宽度 | 操作 | 观察结果 |
|---|---|---|
| 390 / 316 px | STUDIO10 | 输入 STUDIO10 后,$80.00 的示例商品扣了 $8.00,商品小计变为 $72.00。 |
| 1440 / 908 px | STUDIO10 | 输入 STUDIO10 后,$80.00 的示例商品扣了 $8.00,商品小计变为 $72.00。 |
查看 WESWOO 的实测步骤和结果
在同一份预览里按表中顺序操作,中途别重播。观察金额和输入框下的提示:两次 BAD 都报错,但购物车当时的状态不同。
| 依次输入或点击 | 总价 / 发生了什么 |
|---|---|
| BAD | $80.00,首次输入错误 |
| studio10 (前后留空格) | $72.00,优惠生效 |
| 再次输入 STUDIO10 | $72.00,只提示已使用 |
| BAD | $72.00,原优惠仍在 |
| Remove | $80.00,移除原优惠 |
这里是浏览器里的固定金额。把这个反馈接进店铺时,以实际购物车或结账返回的折扣和总价决定提示文字。
正在准备预览
特效说明
已验证的结果
顾客第二次输错优惠码,第一次拿到的折扣还在吗?在这个 80 美元的演示购物车里,先输对、再输错,总价仍是 72 美元。只有点 Remove 才回到 80。
算清这次到底便宜了多少
买家需要看见哪条优惠生效,以及撤回之后要付多少。输入错误时也要把之前生效的优惠交代清楚。
示例源码
查看 3 个源文件HTML · CSS · MJS
<section class="fx receipt" lang="en" aria-label="Discount code trial"><div data-stage><h2>Order summary</h2><dl><div><dt>Merchandise</dt><dd>$80.00</dd></div><div data-saving hidden><dt>STUDIO10</dt><dd>−$8.00</dd></div><div class="total"><dt>Item total</dt><dd data-total>$80.00</dd></div></dl></div>
<div class="coupon"><label for="code">Discount code</label><input id="code" autocapitalize="characters" aria-describedby="hint"><small id="hint">Try STUDIO10 for 10% off the items.</small><div class="row"><button class="primary" data-apply>Apply code</button><button data-remove hidden>Remove</button></div><p data-result role="status"></p></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); } }
.receipt{background:#d8dfd5;color:#233729;display:grid;grid-template-columns:1fr 1fr;padding:0;min-height:225px}
.receipt>div{padding:clamp(16px,3vw,34px)}.receipt dl{margin:18px 0 0}.receipt dl div{display:flex;justify-content:space-between;border-top:1px solid #9fb09d;padding:8px 0}.receipt .total{font-weight:700}.coupon{background:#f8faf5}
.coupon label,.coupon small{display:block}.coupon label{font-weight:650}.coupon input{margin:5px 0;padding:10px;width:100%;border:1px solid #80917e;border-radius:4px;color:#253826;background:#fff}.coupon .row{margin:12px 0 8px}.coupon [data-result]{min-height:1.5em;font-size:14px}.coupon [aria-invalid=true]{border-color:#963d2d}
@media(max-width:520px){.receipt{grid-template-columns:1fr}}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 input=$('#code'), output=$('[data-result]'), remove=$('[data-remove]');
let applied=false;
function apply() {
if(input.value.trim().toUpperCase()!=='STUDIO10') {
input.setAttribute('aria-invalid','true');
output.textContent=applied ? 'Code not recognized. STUDIO10 is still applied.' : 'Code not recognized. Check the spelling.';
} else {
input.removeAttribute('aria-invalid');
output.textContent=applied ? 'STUDIO10 is already applied.' : 'STUDIO10 applied. You saved $8.00.';
applied=true; $('[data-saving]').hidden=false; remove.hidden=false; $('[data-total]').textContent='$72.00';
}
reveal(output);
}
listen($('[data-apply]'),'click',apply);
listen(input,'keydown',event=>{if(event.key==='Enter'&&!event.isComposing){event.preventDefault();apply();}});
listen(remove,'click',()=>{
applied=false;remove.hidden=true;$('[data-saving]').hidden=true;$('[data-total]').textContent='$80.00';
input.value='';input.removeAttribute('aria-invalid');output.textContent='Discount removed.';input.focus({preventScroll:true});reveal(output);
});
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。
绑定编辑器生命周期
用生命周期脚本处理主题编辑器重载、离屏暂停和卸载清理。
使用位置
- 购物车的订单摘要。
交互逻辑
- 有效码更新折扣行;重复应用不重复扣减。
触摸与无障碍
- 回车和点按均可提交,提示在输入框附近。
本效果的接入说明
上线时以购物车或结账返回的折扣分摊及金额为准,提交期间防止重复请求。
上线检查
接入文件
{% 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 Notification Styles,价格为本地演示数据。
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