You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Learn how to create interactive view transitions that adapt in real time to pointer movement."
4
+
draft: true
5
+
head:
6
+
- tag: meta
7
+
attrs:
8
+
property: "og:image"
9
+
content: "/pointer-driven-og.png"
10
+
- tag: meta
11
+
attrs:
12
+
property: "draft"
13
+
content: "true"
14
+
---
15
+
Wouldn't it be cool to have images of whatever complex DOM subtrees of your current page that you can bend and move around as you like?
16
+
17
+
One way to look at the view transition api is this: The API generates snapshots that you can use for animations _…in whatever way you want_.
18
+
19
+
20
+
**In a nutshell**
21
+
* You name the DOM elements you want snapshots for.
22
+
* The View Transition API generates the images for your DOM nodes, no matter how complex the subtree is. And they come in two flavors: bitmaps plus captured CSS properties for the old image and replaced elements for the new images.
23
+
* Those images are rendered in a layer above everything else. It is easy to move your images freely across the viewport. Even more fun with element-scoped view transitions.
24
+
* The magic lasts as long as there exists at least some animation on one of the generated pseudo elements. Doesn't have to be a CSS animation, CSS transitions and WAAPI animations work as well. You can even provide a promise to the API to wait for.
25
+
* If you want, you can cancel unnecessary default animations in your stylesheet. or you keep them and scrub through their timeline by assigning to the currentTime property of their animations.
26
+
27
+
## Benefits of Animating Images instead of DOM Subtrees
28
+
Moving real subtrees through the DOM for animations might quickly become a complex task when the elements are nested in the general layout. . Moving images that render above the normal elements is much easier. Libraries for taking screenshots of DOM elements exist, but they are usually not very accurate. New techniques like
29
+
30
+
Ok, that was a lot of information. To see what is possible with this approach, take a look at the [Forge](https://vtbag.dev/forge) project. It is a small web application that allows you to drag and drop elements into a forge and combine them into new elements. The Forge uses the View Transition API to animate the elements as they are dragged around.
31
+
32
+
Here are the details step by step.
33
+
34
+
## Drag-Driven View Transitions
35
+
36
+
Grab and drag your transition pseudo-elements.
37
+
38
+
The natural way to find out how to forge new elements in the example is to just try it out. We want to visually move the element from the centre into one of the forges to see what happens.
39
+
40
+
This is very similar to the typical drag and drop code:
0 commit comments