Every little fish swimming around is a visitor on this page right now, and one of them is you ( ´ ▽ ` )ノ If they get in the way of reading, feel free to turn them off.
VFX Transition
transitionWe previously used an SVG Filter implementation. Not only did it occupy the filter property on style, it was also limited by SVG support and other issues—in short, there were quite a lot of constraints. ( ˘•ω•˘ )
Thanks to snapDOM, we can easily put the DOM onto a canvas and create all sorts of cool effects! ヾ(◍'౪`◍)ノ゙
Tech Keywords
Section titled “Tech Keywords”| Name | Description |
|---|---|
| Canvas 2D API | Basic 2D drawing API that efficiently renders graphics too complex for the DOM |
| Canvas Shader | Written in GLSL and executed directly on the GPU, faster than the Canvas 2D API but harder to master |
| DOM to Image | Converts DOM elements into images, based on SVG foreignObject |
| Vue Transition | Built-in component that animates the enter/leave of a single element |
| Anime.js | Lightweight JavaScript animation library |
| JS Animation | JavaScript-driven animation for more complex, precise control; popular libraries include GSAP and anime.js |
| CSS Anchor Positioning | New CSS feature that positions elements relative to other elements (anchors) |
Usage examples
Section titled “Usage examples”Basic usage
Section titled “Basic usage”Its usage is the same as Vue’s built-in Transition component.
<template> <div class="w-full flex flex-col gap-4 example-wrap"> <div class="example-ctrl flex flex-col gap-4"> <base-checkbox v-model="visible" :label="$t('show')" /> </div>
<div class="flex justify-center"> <transition-vfx> <div v-if="visible" class="card rounded p-6" > {{ $t('hello') }} </div> </transition-vfx> </div> </div></template>
<script setup lang="ts">import { ref } from 'vue'import BaseCheckbox from '../../base-checkbox.vue'import TransitionVfx from '../transition-vfx.vue'
const visible = ref(true)</script>
<style scoped lang="sass">.card background-color: light-dark(#edf0f2, #383e45)</style>Enter & leave
Section titled “Enter & leave”You can specify different effects for enter and leave.

<template> <div class="w-full flex flex-col gap-4"> <div class="example-ctrl grid grid-cols-4 items-center gap-2"> <select-stepper v-model="enterName" :label="t('enterEffect')" :options="options" class="col-span-2" />
<select-stepper v-model="leaveName" :label="t('leaveEffect')" :options="options" class="col-span-2" />
<div class="col-span-6 border rounded-lg duration-300" :class="{ 'cursor-not-allowed opacity-30': isTransitioning, 'cursor-pointer': !isTransitioning, }" > <base-checkbox v-model="visible" :label="t('show')" class="w-full cursor-pointer p-4" :class="{ 'pointer-events-none': isTransitioning }" /> </div> </div>
<div class="min-h-[60vmax] flex items-center justify-center md:min-h-[50vh]" :class="{ 'pointer-events-none': isTransitioning }" > <transition-vfx :enter-params="params.enter" :leave-params="params.leave" @enter="isTransitioning = true" @leave="isTransitioning = true" @after-enter="isTransitioning = false" @after-leave="isTransitioning = false" > <div v-if="visible" class="card flex flex-col items-center gap-4 border rounded-xl p-6" > <img src="/low/profile.webp" alt="" class="mb-4 h-[180px] w-[180px] overflow-hidden border-4 border-white rounded-full shadow-xl" >
<div class="text-xl font-bold"> {{ t('codfishName') }} </div>
<base-input v-model="text" class="text-center md:w-[22rem]" :class="{ 'font-bold': styles.bold, 'italic': styles.italic, }" />
<div class="flex gap-2"> <base-checkbox v-model="styles.bold" :label="t('bold')" />
<base-checkbox v-model="styles.italic" :label="t('italic')" /> </div> </div> </transition-vfx> </div> </div></template>
<script setup lang="ts">import { computed, ref } from 'vue'import { useI18n } from 'vue-i18n'import BaseCheckbox from '../../base-checkbox.vue'import BaseInput from '../../base-input.vue'import SelectStepper from '../../select-stepper.vue'import TransitionVfx from '../transition-vfx.vue'import { TransitionName } from '../type'
const { t } = useI18n()
const text = ref(t('inputPlaceholder'))const styles = ref({ bold: false, italic: false,})
const isTransitioning = ref(false)const visible = ref(true)const enterName = ref<`${TransitionName}`>('shatter')const leaveName = ref<`${TransitionName}`>('shatter')
const params = computed(() => ({ enter: { name: enterName.value }, leave: { name: leaveName.value },}))
const options = Object.values(TransitionName)</script>
<style scoped lang="sass">.card background-color: light-dark(#edf0f2, #383e45)</style>How it works
Section titled “How it works”-
Intercept
Transitionevents -
Create a canvas that covers the element and position it using CSS Anchor
Anchor name and positioning styles are written inline rather than in global styles, so class names shared with other components cannot override each other in a production build. Where the browser lacks anchor positioning, measured coordinates take over.
-
Use
snapDOMto draw the DOM onto the canvas -
During
enterandleave, hide the original DOM and show the canvas, like a stunt double ( •̀ ω •́ )✧ -
Implement the
enterandleaveanimation logic on the canvas -
After the animation finishes, restore the original DOM and hide the canvas
Source code
Section titled “Source code”interface Props { appear?: boolean; enterParams?: TransitionParams; leaveParams?: TransitionParams; duration?: number;}const emit = defineEmits<{ (e: 'enter'): void; (e: 'afterEnter'): void; (e: 'leave'): void; (e: 'afterLeave'): void;}>()const slots = defineSlots<{ default?: () => unknown;}>()If you have any suggestions or questions, feel free to email me( ´ ▽ ` )ノ
If you like cool components, feel free to " Buy me a cup of coffee " to show your support!