ps-view-transitions
Skill4 starsChanged 14 days agoMITView on GitHub
Adds View Transitions to a PrestaShop child theme: soft fade between pages, animated product-list swap when filtering/sorting/paginating (facets AJAX), and the shared-element morph from a product tile image to the product page photo and back. Pure CSS plus small vanilla JS, no libraries. Use when the user asks for view transitions, page transitions, "transiciones entre paginas", animated filters, "que los productos no salten al filtrar", a miniatura-to-ficha image animation, or a more polished/app-like storefront UX on a PS 8/9 theme (Hummingbird, Classic, Panda, ElementFlow children). Also use to debug a transition that silently does nothing or aborts.
In this repository37 other files it gives its agents.
- blast-radiusSkill
- elementflow-kbSkill
- gitlab-changelog-releaseSkill
- gitlab-ci-quality-gatesSkill
- gitlab-project-bootstrapSkill
- gitlab-security-setupSkill
- gitlab-wiki-bootstrapSkill
- lando-checkSkill
- lando-img-placeholderSkill
- lando-mail-smtpSkill
- lando-setupSkill
- mallard-releaseSkill
- mr-flowSkill
- no-commentsSkill
- paginated-report-pdfSkill
- panda-kbSkill
- ploi-prestashop-deploySkill
- prestashop-kbSkill
- ps-consoleSkill
- ps-css-buildSkill
- ps-demo-userSkill
- ps-email-previewSkill
- ps-image-regenSkill
- ps-invoice-previewSkill
- ps-new-projectSkill
- ps-one-page-checkoutSkill
- ps-project-docSkill
- ps-security-auditSkill
- ps-storefront-polishSkill
- ps-theme-cacheSkill
- ps-translateSkill
- ps-watchSkill
- reflectSkill
- show-me-your-workSkill
- skill-authorSkill
- task-contextSkill
- verify-ps-projectSkill
The file
Files
PS View Transitions
Montado y probado en ps9-espaciopiessanos (PS 9.2, child de Hummingbird, Chrome 154).
Tres capas independientes: puedes aplicar solo las que quieras.
Antes de empezar
- Confirma que el tema usa
core.jsde PS para facetas (emiteupdateProductList). Hummingbird y Classic sí; temas con listado propio (Panda/ElementFlow con filtros de módulo) no: capa 2 no aplica tal cual. - Localiza y apunta estos selectores del proyecto (los de abajo son los de Hummingbird):
- lista:
#js-product-list(en HummingbirdTheme.selectors.listing.list) - tarjeta:
.js-product-miniaturecondata-id-product - imagen de tarjeta:
.product-miniature__image - foto principal de ficha:
.page-product .product__carousel .carousel-item.active img - header sticky:
#header
- lista:
- Respeta
prefers-reduced-motionen todo. - Dónde va el código: CSS en el
custom.cssdel child (o su partial si hay build, verps-css-build), JS enassets/js/custom.js. No toques el core ni el padre.
Capa 1: entre páginas (CSS, sin JS)
@view-transition{navigation:auto}
#header{view-transition-name:site-header}
::view-transition-group(site-header){z-index:1}
::view-transition-old(root),::view-transition-new(root){animation-duration:.18s}
@media (prefers-reduced-motion:reduce){
@view-transition{navigation:none}
::view-transition-group(*),::view-transition-old(*),::view-transition-new(*){animation:none!important}
}El header con nombre propio evita que se desvanezca con la página. Sin soporte del navegador no pasa nada: navegación normal.
Capa 2: filtrar/ordenar/paginar sin saltos (JS + CSS)
El core hace el swap del listado de forma síncrona dentro del evento updateProductList. Se envuelve prestashop.emit:
(function () {
if (!document.startViewTransition || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
function init() {
var p = window.prestashop;
if (!p || typeof p.emit !== 'function' || p.__vt) return;
p.__vt = true;
var listSel = (window.Theme && Theme.selectors && Theme.selectors.listing && Theme.selectors.listing.list) || '#js-product-list';
var emit = p.emit;
var tag = function () {
document.querySelectorAll(listSel + ' .js-product-miniature').forEach(function (el) {
el.style.viewTransitionName = 'p-' + el.getAttribute('data-id-product');
});
};
p.emit = function (ev) {
var self = this, args = arguments;
if (ev !== 'updateProductList' || !document.querySelector(listSel)) return emit.apply(self, args);
var root = document.documentElement;
root.classList.add('vt-list');
tag();
var t = document.startViewTransition(function () { emit.apply(self, args); tag(); });
var done = function () { root.classList.remove('vt-list'); };
t.finished.then(done, done);
return self;
};
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init);
else init();
})();/* solo se animan las tarjetas, el resto de la pagina queda quieto */
.vt-list::view-transition-old(root),.vt-list::view-transition-new(root){animation:none}
.vt-list::view-transition-group(*){animation-duration:.3s;animation-timing-function:cubic-bezier(.22,1,.36,1)}- Los nombres de las tarjetas se ponen por JS y solo dentro del listado, no en la plantilla: si el mismo producto sale dos veces en una página (carrusel en home), el nombre duplicado aborta la transición.
- Si hay drawer + velo de filtros, ver Gotchas 2 y 3: hay que nombrarlos y fijar su z-index.
Capa 3: miniatura ↔ ficha (CSS + JS + script en head)
Ir a la ficha. Al salir, se nombra la imagen de la tarjeta pulsada (pageswap); la ficha nombra su foto por CSS:
(function () {
if (!('PageSwapEvent' in window) || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
var clicked = null;
document.addEventListener('click', function (e) {
var link = e.target.closest('.js-product-miniature a[href]');
clicked = link && !(e.metaKey || e.ctrlKey || e.shiftKey || e.button) ? link.closest('.js-product-miniature') : null;
}, true);
addEventListener('pageswap', function (e) {
if (!e.viewTransition || !clicked) return;
var img = clicked.querySelector('.product-miniature__image');
clicked = null;
if (!img) return;
img.style.viewTransitionName = 'product-image';
e.viewTransition.finished.finally(function () { img.style.viewTransitionName = ''; });
});
})();.page-product .product__carousel .carousel-item.active img{view-transition-name:product-image}
::view-transition-group(product-image){animation-duration:.4s;animation-timing-function:cubic-bezier(.22,1,.36,1)}
::view-transition-old(product-image),::view-transition-new(product-image){height:100%;object-fit:cover}object-fit:cover evita deformar la foto cuando la tarjeta (cuadrada) y la ficha (vertical) tienen proporciones distintas.
Volver al listado. Script inline en templates/_partials/head.tpl del child (dentro de {literal}), porque pagereveal se dispara en el primer render, antes de los scripts de abajo:
(function () {
if (!('PageRevealEvent' in window) || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
var KEY = 'vtTile';
document.addEventListener('click', function (e) {
var tile = e.target.closest('.js-product-miniature');
if (tile && e.target.closest('a[href]')) sessionStorage.setItem(KEY, tile.getAttribute('data-id-product'));
}, true);
addEventListener('pagereveal', function (e) {
var id = sessionStorage.getItem(KEY);
var nav = performance.getEntriesByType('navigation')[0];
if (!e.viewTransition || !id || !nav || nav.type !== 'back_forward') return;
sessionStorage.removeItem(KEY);
var img = document.querySelector('#js-product-list .js-product-miniature[data-id-product="' + id + '"] .product-miniature__image');
if (!img) return;
img.style.viewTransitionName = 'product-image';
e.viewTransition.finished.finally(function () { img.style.viewTransitionName = ''; });
});
})();La clave solo se consume en la rama back_forward; si se borrara antes, la propia llegada a la ficha la gastaría.
Gotchas (cada uno costó tiempo)
- Dos elementos con el mismo
view-transition-nameabortan TODA la transición, sin error visible (InvalidStateError: Snapshot capture failedentransition.ready). Ojo con elementos ocultos: en Hummingbird conviven el drawer de escritorio y el offcanvas móvil. - Orden de capas: los grupos que solo existen en el estado nuevo (tarjetas que entran) se pintan encima de los antiguos. Si hay velo/drawer, dales nombre (solo al que está abierto:
.drawer.is-open,.offcanvas.show, y el velo) yz-indexexplícito en::view-transition-group(...): header 1, velo 2, drawer 3. pagerevealva antes que los scripts del final del body. Todo lo que necesite la página nueva en el primer render: CSS o script inline en<head>.- No metas assets nuevos por
theme.ymlsi el tema ya está instalado: PS cachea su config enconfig/themes/<tema>/shop1.json(gitignored) y no surte efecto hasta resetear el tema. Por eso el script del head va inline enhead.tpl. - El fichero compilado CCC conserva el nombre (
theme-xxxx.css) aunque cambie su contenido: recarga dura al probar. Borrathemes/<child>/assets/cache/*y carga una página en el navegador para regenerar (concurlno se regenera). - La transición entre documentos tiene tope de ~4 s: si la página nueva tarda más en renderizar, se salta. Local lento (Lando) puede enmascarar el efecto.
- Las navegaciones por CDP/automatización no disparan la transición entre documentos. Pruébalo con clics reales (o
a.click()desde la página). lando php bin/console cache:clearse queda sin memoria en el warmup:lando php -d memory_limit=2G bin/console cache:clear --no-warmup(ambos entornos).
Cómo probar
- Listado: hacer clic en un filtro;
document.startViewTransitionenvuelto debe registrar 1 llamada,readyyfinishedsin error, ydocument.documentElement.classNamedebe volver a estar sinvt-list. - Capas: para ver un fotograma intermedio, alargar la duración (
::view-transition-group(*),::view-transition-old(*),::view-transition-new(*){animation-duration:8s!important}) y capturar a mitad. Con el drawer abierto, ninguna tarjeta debe verse por encima del velo. - Nombres duplicados: con la clase
vt-listpuesta, listar los elementos congetComputedStyle(el).viewTransitionName !== 'none'y comprobar que no hay repetidos. - Miniatura → ficha: clic real en una tarjeta, comprobar que existe exactamente un elemento con
product-imageen la ficha. Volver conhistory.back()y comprobar que la clavevtTiledesaparece.
Costes a tener en cuenta (no es gratis del todo)
- Navegadores sin soporte: se ve la navegación normal, sin efecto.
- Cada elemento con nombre es una capa: con listados largos (>40 tarjetas con nombre) vigila memoria; limita a las visibles si hace falta.
- Mantenimiento por proyecto: los selectores y los drawers cambian. Revisar la sección "Antes de empezar" en cada tema.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

