|
15 | 15 | <button>Click</button> |
16 | 16 | <div class="outer"> |
17 | 17 | <div class="container"> |
18 | | - <div |
19 | | - id="ball" |
20 | | - style="view-transition-name: ball; width:200px; height: 200px;border-radius: 50%; background-color: darkgreen" |
21 | | - > |
| 18 | + <div id="ball"> |
22 | 19 | <ul> |
23 | 20 | <li>item 1</li> |
24 | 21 | <li>item 2</li> |
|
46 | 43 | }); |
47 | 44 |
|
48 | 45 | document.addEventListener("click", () => { |
49 | | - console.log("state change"); |
50 | 46 |
|
51 | 47 | container.startViewTransition!(() => { |
52 | | - const state = container.getAttribute("data-state"); |
53 | | - container.style.alignItems = |
54 | | - state !== "2" ? "flex-start" : "flex-end"; |
55 | | - container.setAttribute("data-state", state !== "2" ? "2" : "1"); |
| 48 | + container.setAttribute( |
| 49 | + "data-state", |
| 50 | + container.getAttribute("data-state") !== "2" ? "2" : "1", |
| 51 | + ); |
| 52 | + }).ready.then(()=>{ |
| 53 | + container.style.viewTransitionScope = "none"; |
| 54 | + container.insertAdjacentHTML("beforeend","<div class=new-element>New Element</div") |
| 55 | + const style = getComputedStyle(container); |
| 56 | + console.log(style.viewTransitionScope) |
| 57 | + outer.startViewTransition!(); |
56 | 58 | }); |
57 | 59 | }); |
58 | 60 | </script> |
|
77 | 79 | } |
78 | 80 |
|
79 | 81 | .container { |
| 82 | + view-transition-name: none; |
80 | 83 | display: flex; |
81 | 84 | flex-direction: column; |
82 | 85 | align-items: flex-end; |
83 | 86 | justify-content: center; |
84 | 87 | min-height: 100vh; |
85 | 88 | padding: 16px; |
86 | 89 | gap: 12px; |
| 90 | + view-transition-scope: none !important; |
87 | 91 | } |
88 | 92 |
|
89 | | - ::view-transition-group(ball) { |
| 93 | + .new-element { |
| 94 | + view-transition-name: match-element; |
| 95 | + } |
| 96 | + #ball { |
90 | 97 | view-transition-name: ball; |
| 98 | + width: 200px; |
| 99 | + height: 200px; |
| 100 | + border-radius: 50%; |
| 101 | + background-color: darkgreen; |
91 | 102 | } |
92 | | - .container { |
93 | | - view-transition-name: none; |
94 | | - view-transition-scope: none !important; |
95 | | - &::view-transition-group(ball) { |
96 | | - view-transition-scope: none !important; |
97 | | - } |
| 103 | + |
| 104 | + .container[data-state="2"] { |
| 105 | + align-items: flex-start; |
98 | 106 | } |
99 | 107 | </style> |
100 | 108 | </html> |
0 commit comments