vue3+element-plus暗黑模式切换动画圆弧过渡效果
更新时间:2025年01月10日 10:52:10 作者:Cheng Lucky
文章介绍了如何在Vue 3和Element Plus中实现暗黑模式的切换,并通过动画和圆弧过渡效果提升用户体验,本文给大家介绍的非常详细,感兴趣的朋友一起看看吧
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;
});
});
};到此这篇关于vue3+element-plus暗黑模式切换动画圆弧过渡效果的文章就介绍到这了,更多相关vue element-plus暗黑模式切换内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
Vue + Element 实现按钮指定间隔时间点击思路详解
这篇文章主要介绍了Vue + Element 实现按钮指定间隔时间点击,实现思路大概是通过加一个本地缓存的时间戳,通过时间戳计算指定时间内不能点击按钮,具体实现代码跟随小编一起看看吧2023-12-12
vue form表单post请求结合Servlet实现文件上传功能
这篇文章主要介绍了vue form表单post请求结合Servlet实现文件上传功能,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧2021-01-01
vue中electron框架自定义外部配置文件的配置与读取办法
使用Electron开发本地跨平台的本地程序时,有时需要添加一些程序的配置文件,下面这篇文章主要给大家介绍了关于vue中electron框架自定义外部配置文件的配置与读取的相关资料,需要的朋友可以参考下2023-12-12


最新评论