An open API service indexing awesome lists of open source software.

https://github.com/rudrodip/theme-toggle-effect

theme toggle effect using view transitions api
https://github.com/rudrodip/theme-toggle-effect

theme-toggle view-transitions-api

Last synced: 3 months ago
JSON representation

theme toggle effect using view transitions api

Awesome Lists containing this project

README

        

# Theme toggle effect

Here's how we can create theme toggle effect using view transitions api

This is literally the two lines of js you need

```js
if (!document.startViewTransition) switchTheme()
document.startViewTransition(switchTheme);
```

Then you can write your css as you wish to

For example

```css
::view-transition-group(root) {
animation-timing-function: var(--expo-out);
}

::view-transition-new(root) {
mask: url('data:image/svg+xml,') center / 0 no-repeat;
animation: scale 1s;
}

::view-transition-old(root),
.dark::view-transition-old(root) {
animation: none;
z-index: -1;
}
.dark::view-transition-new(root) {
animation: scale 1s;
}

@keyframes scale {
to {
mask-size: 200vmax;
}
}
```

This will create a nice circular transition effect when you switch themes.
![theme-toggle](.github/assets/vta.gif)

For more examples, visit [theme-toggle.rdsx.dev](https://theme-toggle.rdsx.dev)

Don't forget to star the repo if you like it

Follow me on [x (twitter)](https://x.com/rds_agi) & [github](https://github.com/rudrodip)