diff --git a/lib/handle-toggle-click.ts b/lib/handle-toggle-click.ts index ab60734..c5e0f23 100644 --- a/lib/handle-toggle-click.ts +++ b/lib/handle-toggle-click.ts @@ -11,8 +11,31 @@ async function startCircleAnimation( } } + const removeTemporaryStyles = () => { + const style = document.getElementById('temp-theme-transition-styles') + if (style) { + document.head.removeChild(style) + } + } + + const injectTemporaryStyles = () => { + removeTemporaryStyles() + const style = document.createElement('style') + style.id = 'temp-theme-transition-styles' + style.textContent = ` + ::view-transition-old(root), + ::view-transition-new(root) { + animation: none; + mix-blend-mode: normal; + } + ` + document.head.appendChild(style) + } + injectTemporaryStyles() + if (typeof doc.startViewTransition !== 'function') { callback() + removeTemporaryStyles() return } diff --git a/lib/theme-script.astro b/lib/theme-script.astro index d8ed964..b774edd 100644 --- a/lib/theme-script.astro +++ b/lib/theme-script.astro @@ -1,10 +1,34 @@ - diff --git a/website/components/theme-toggle-button.astro b/website/components/theme-toggle-button.astro index 748ce69..acf0752 100644 --- a/website/components/theme-toggle-button.astro +++ b/website/components/theme-toggle-button.astro @@ -9,7 +9,11 @@ diff --git a/website/pages/index.astro b/website/pages/index.astro index 93cd0b4..b9cbc6c 100644 --- a/website/pages/index.astro +++ b/website/pages/index.astro @@ -14,6 +14,7 @@ import Layout from '../layouts/Layout.astro' >Add a ripple-style theme toggle animation to your Astro project with ease + about