view-transitions
БесплатноБез исполняемых скриптовНе проверенTeaches the View Transitions API for animating DOM changes. Use when you want smooth animated transitions between pages or UI states without manual animation…
от PatternsDev★ 261 звезда на GitHubОб этом скилле
Animating View Transitions
Table of Contents
When to Use
- Use this when you want to animate transitions between different page states or navigations
- This is helpful for creating polished, app-like navigation experiences in web applications
Instructions
- Use
document.startViewTransition(callback)to animate DOM changes - Assign unique
view-transition-nameCSS properties to elements that should transition between states - Check for browser support before using the API (
if (document.startViewTransition)) - Minimize the time the DOM is frozen by starting transitions after data fetching completes
- Consider CSS animation fallbacks for browsers that don't yet support the View Transitions API
Details
Introduction to View Transitions
The View Transitions API offers a simple way to transition any visual DOM change from one state to the next. This might include small changes such as toggling some content, or broader changes such as navigating from one page to the next.
The JavaScript API centers around document.startViewTransition(callback), where callback is a function that typically updates the DOM to the new state.
Let's take toggling a <details> element as a simple example:
if (document.startViewTransition) {
// (check for browser support)
document.addEventListener("click", function (event) {
if (event.target.matches("summary")) {
event.preventDefault(); // (we'll toggle the element ourselves)
const details = event.target.closest("details");
document.startViewTransition(() => details.toggleAttribute("open"));
}
});
}
document.startViewTransition takes a screenshot of the current DOM before calling the callback. Here, our callback just toggles the open attribute. Once complete, the browser can then transition between the initial screenshot and the new version.
These old and new versions are presented as pseudo elements and can be referenced in CSS with ::view-transition-old(root) and ::view-transition-new(root) respectively. For example, to emphasize the transition, we can lengthen the animation-duration like so:
::view-transition-old(root),
::view-transition-new(root) {
animation-duration: 2s;
}
View transitions are also capable of animating multiple changes with more advanced animations that go beyond the default crossfade. By giving specific elements a CSS view-transition-name, and a containment of layout or paint, the API gives developers granular control over how the elements transition, including their width, height, and position. These advanced transitions can really help communicate the flow from one page to the next.
Take a photo gallery as an example: the most obvious transition is the size and position of the photo, which is automatically achieved when the <img> element on each page is given the same unique view-transition-name, and a CSS containment value of layout. The view-transition-names can be hard-coded in the style attributes, or added dynamically (e.g. in a onclick handler), as long as they're unique to the page and added before the transition is started.
The photo details beneath require a little more styling. We give each line element its own view-transition-name:
figcaption h2 {
contain: layout;
view-transition-name: photo-heading;
}
figcaption div {
contain: layout;
view-transition-name: photo-location-time;
}
figcaption dl {
contain: layout;
view-transition-name: photo-meta;
}
This generates transition groups for each area, which are just like the new/old screenshots mentioned earlier, but only cover an area of the page rather than the whole document. And just as the whole document transition elements could be targeted with ::view-transition-old(root) and ::view-transition-new(root), these transition groups can be targeted with ::view-transition-old(NAME) and ::view-transition-new(NAME). Note that the details text is not present on the photo grid page, therefore when transitioning from the grid to the photo page, there'll only be a ::view-transition-new(NAME), not a ::view-transition-old(NAME), and vice versa when navigating the other way. So we can target these cases using the :only-child pseudo class and customize the animation. For the photo-heading group:
/* Enter */
::view-transition-new(photo-heading):only-child {
animation: 300ms ease 50ms both fade-in, 300ms ease 50ms both slide-up;
}
/* Exit */
::view-transition-old(photo-heading):only-child {
animation: 200ms ease 150ms both fade-out, 200ms ease 150ms both slide-down;
}
That's the basics of the API. Jake Archibald's excellent View Transitions article covers the details well. For now, let's see how
Установить view-transitions в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobFAQ
Что делает скилл view-transitions?
Teaches the View Transitions API for animating DOM changes. Use when you want smooth animated transitions between pages or UI states without manual animation code.
Как установить скилл view-transitions?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл view-transitions запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic