vue3+element-plus暗黑模式切換動畫圓弧過渡效果
更新時間:2025年01月10日 10:52:10 作者:Cheng Lucky
文章介紹了如何在Vue 3和Element Plus中實現(xiàn)暗黑模式的切換,并通過動畫和圓弧過渡效果提升用戶體驗,本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
vue3+element-plus暗黑模式切換動畫圓弧過渡
效果
html
<div class="toggle" ref="switchRef" @click.stop="toggleDark()"> <el-icon v-show="!isDark" :size="30"><Moon /></el-icon> <el-icon v-show="isDark" :size="30"><Sunny /></el-icon> </div>
ts
import { useDark } from '@vueuse/core'; const isDark = useDark(); //獲取切換元素的ref const switchRef = ref<HTMLElement>(); const toggleDark = () => { // 若瀏覽器不支持 View Transitions if (!document.startViewTransition) { return true; } return new Promise(resolve => { const switchEl = switchRef.value as HTMLElement; const rect = switchEl.getBoundingClientRect(); const x = rect.left + rect.width / 2; const y = rect.top + rect.height / 2; const radius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y)); const transition = document.startViewTransition(() => { resolve(true); }); transition.ready.then(() => { const clipPath = [`circle(0px at ${x}px ${y}px)`, `circle(${radius}px at ${x}px ${y}px)`]; document.documentElement.animate( { clipPath, }, { duration: 400, easing: 'ease-in', pseudoElement: '::view-transition-new(root)', } ); isDark.value = !isDark.value; }); }); };
到此這篇關(guān)于vue3+element-plus暗黑模式切換動畫圓弧過渡效果的文章就介紹到這了,更多相關(guān)vue element-plus暗黑模式切換內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VUE使用router.push實現(xiàn)頁面跳轉(zhuǎn)和傳參方式
這篇文章主要介紹了VUE使用router.push實現(xiàn)頁面跳轉(zhuǎn)和傳參方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01vue使用vue-json-viewer插件展示JSON格式數(shù)據(jù)的方法
這篇文章主要給大家介紹了關(guān)于vue使用vue-json-viewer插件展示JSON格式數(shù)據(jù)的相關(guān)資料,前端使用這個插件可以方便展現(xiàn)出json格式的數(shù)據(jù),下載引入使用代碼可直接使用,需要的朋友可以參考下2024-05-05VUE2 前端實現(xiàn) 靜態(tài)二級省市聯(lián)動選擇select的示例
下面小編就為大家分享一篇VUE2 前端實現(xiàn) 靜態(tài)二級省市聯(lián)動選擇select的示例。具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02