Skip to content

How to get ripple effect on theme change? #19903

Answered by kingyue737
1Luc1 asked this question in Q&A
Discussion options

You must be logged in to vote

Via View Transition API

Here is an example:

<script setup lang="ts">
import { useToggle, useDark } from '@vueuse/core'
const theme = useTheme()
const isDark = useDark({
  onChanged(dark: boolean) {
    theme.global.name.value = dark ? 'dark' : 'light'
  },
})

const isAppearanceTransition =
  document.startViewTransition &&
  !window.matchMedia('(prefers-reduced-motion: reduce)').matches

const toggleDark = useToggle<true, false | null>(isDark)
function transitDark(event?: MouseEvent) {
  if (!isAppearanceTransition || !event) {
    toggleDark()
    return
  }
  const x = event.clientX
  const y = event.clientY
  const endRadius = Math.hypot(
    Math.max(x, innerWidth - x),
    Math.max(y, 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@1Luc1
Comment options

@kingyue737
Comment options

@1Luc1
Comment options

Answer selected by 1Luc1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants