当前位置: 首页 > news >正文

新变更营业执照注册号查了发现之前有备案过网站了seo咨询推广

新变更营业执照注册号查了发现之前有备案过网站了,seo咨询推广,厦门网站推广公司哪家好,wordpress修改手机模板在开发中,为用户提供具有视觉冲击力的反馈是一种提升用户体验的好方法。今天,我们将结合 Vue 框架、canvas-confetti 和 Lottie 动画,创建一个动态对话框动画,其中包含炫酷的烟花特效。 效果图: 效果简介 当用户触发…

在开发中,为用户提供具有视觉冲击力的反馈是一种提升用户体验的好方法。今天,我们将结合 Vue 框架、canvas-confetti 和 Lottie 动画,创建一个动态对话框动画,其中包含炫酷的烟花特效。

效果图:

效果简介

当用户触发特定事件时:

  1. 弹出一个对话框,加载基于用户等级的 Lottie 动画。
  2. 配合对话框的展示,启动烟花特效(canvas-confetti),模拟庆祝场景。
  3. 用户关闭对话框时,清除动画和特效。

使用的技术栈

  • Vue 3: 构建响应式用户界面。
  • Lottie: 显示矢量动画,支持用户等级的动态变化。
  • canvas-confetti: 用于生成烟花效果,支持细粒度的控制和动画定制。

实现步骤

1. 安装依赖
npm install canvas-confetti lottie-web

2. 代码实现

以下是核心代码的分步解析:

初始化状态和依赖
import confetti from 'canvas-confetti'
import lottie from 'lottie-web'
import { watchEffect, computed, ref } from 'vue'
import { useGlobalStore } from '@/stores/global'
import { useUserStore } from '@/stores/user'

  • 引入 canvas-confettilottie-web
  • 使用 useGlobalStoreuseUserStore 来获取全局状态和用户数据。

动态动画加载

通过 watchEffect 监听对话框状态,动态加载 Lottie 动画和烟花效果:

 
watchEffect(() => {if (value.value) {// 加载 Lottie 动画animation = lottie.loadAnimation({container: animationContainer.value,renderer: 'svg',loop: true,autoplay: true,animationData: getLottieFileByUserLevel(),})// Lottie 动画加载完成后触发烟花效果animation.addEventListener('DOMLoaded', startConfetti)} else {// 清除动画和烟花if (animation) {animation.destroy()animation = null}if (animationFrameId) {cancelAnimationFrame(animationFrameId)animationFrameId = null}}
})


创建烟花效果

通过 requestAnimationFrame 控制粒子效果的动态生成:

const startConfetti = () => {const duration = 15 * 1000 // 烟花持续时间const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 2100 }const animationEnd = Date.now() + durationconst frame = () => {const timeLeft = animationEnd - Date.now()if (timeLeft <= 0) {if (animationFrameId) cancelAnimationFrame(animationFrameId)return}const particleCount = 10 * (timeLeft / duration)confetti({...defaults,particleCount,origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 },})confetti({...defaults,particleCount,origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 },})// 循环调用animationFrameId = requestAnimationFrame(frame)}frame()
}

这里的 randomInRange 函数用来随机生成粒子发射的方向和范围:

function randomInRange(min: number, max: number) {return Math.random() * (max - min) + min
}


根据用户等级加载 Lottie 动画

不同的用户等级对应不同的动画文件:

const getLottieFileByUserLevel = () => {let level = userStore.userLevelif (level === 2) {return Level02Lottie} else if (level === 3) {return Level03Lottie} else if (level === 4) {return Level04Lottie} else if (level === 5) {return Level05Lottie} else if (level === 6) {return Level06Lottie} else {return Level01Lottie}
}


3. 完整代码
<script lang="ts" setup>
import confetti from 'canvas-confetti'
import { watchEffect, computed, ref } from 'vue'
import { useGlobalStore } from '@/stores/global'
import { useUserStore } from '@/stores/user'
import lottie from 'lottie-web'
import Level01Lottie from '@/assets/lottie/Level01.json'
import Level02Lottie from '@/assets/lottie/Level02.json'
import Level03Lottie from '@/assets/lottie/Level03.json'
import Level04Lottie from '@/assets/lottie/Level04.json'
import Level05Lottie from '@/assets/lottie/Level05.json'
import Level06Lottie from '@/assets/lottie/Level06.json'const globalStore = useGlobalStore()
const userStore = useUserStore()
const props = defineProps(['modelValue'])
const emit = defineEmits(['update:modelValue'])
const animationContainer = ref()
let animation: any = null
let animationFrameId: number | null = nullconst value = computed({get() {return props.modelValue},set(value) {emit('update:modelValue', value)},
})const beforeClose = () => {globalStore.fireworkVisable.show = false
}// Confetti effect function with requestAnimationFrame
function randomInRange(min: number, max: number) {return Math.random() * (max - min) + min
}const getLottieFileByUserLevel = () => {let level = userStore.userLevelif (level === 2) {return Level02Lottie} else if (level === 3) {return Level03Lottie} else if (level === 4) {return Level04Lottie} else if (level === 5) {return Level05Lottie} else if (level === 6) {return Level06Lottie} else {return Level01Lottie}
}const startConfetti = () => {const duration = 15 * 1000const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 2100 }const animationEnd = Date.now() + durationconst frame = () => {const timeLeft = animationEnd - Date.now()if (timeLeft <= 0) {if (animationFrameId) cancelAnimationFrame(animationFrameId)return}const particleCount = 10 * (timeLeft / duration)confetti({...defaults,particleCount,origin: { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 },})confetti({...defaults,particleCount,origin: { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 },})// Continue the animation loopanimationFrameId = requestAnimationFrame(frame)}frame()
}watchEffect(() => {if (value.value) {// Load lottie animationanimation = lottie.loadAnimation({container: animationContainer.value,renderer: 'svg',loop: true,autoplay: true,animationData: getLottieFileByUserLevel(),})// Start confetti after lottie loadsanimation.addEventListener('DOMLoaded', startConfetti)} else {// Destroy lottie animation and cancel confetti animationif (animation) {animation.destroy()animation = null}if (animationFrameId) {cancelAnimationFrame(animationFrameId)animationFrameId = null}}
})
</script><template><div class="tipBox"><el-dialog v-model="value" title="" :before-close="beforeClose"><div ref="animationContainer" style="width: 100%; height: 100%"></div></el-dialog></div>
</template><style lang="scss" src="./style.scss" scoped />

 


总结

以上实现为用户提供了动态且炫酷的视觉体验:

  1. 对话框弹出时加载用户特定的动画。
  2. 使用 canvas-confetti 模拟烟花特效,持续 15 秒。
  3. 对话框关闭时清理资源,避免性能问题。

这种效果非常适用于用户晋级、任务完成等场景,希望本文能对你有所启发!

http://www.yidumall.com/news/44948.html

相关文章:

  • 同ip网站做排名seo百度首页网址
  • 企业网站制作公司盈利万网域名查询工具
  • 做微商什么是官方网站百度seo刷排名网址
  • 做网站和易语言自己的网站怎么样推广优化
  • 职友集 一家做职业点评的网站seo专员是指什么意思
  • ui网站界面运用搜索引擎营销的案例
  • php网站安装包制作云南seo简单整站优化
  • 一块钱购物网站市场调研方法
  • 防城港做网站的聊石家庄seo
  • wordpress媒体库备份广东百度seo
  • 有哪些网站做美食的图片很精致充电宝seo关键词优化
  • 高端做网站公司哪家好怎么投放广告
  • 信息空间网站好app开发用什么软件
  • pb代做网站网络项目发布网
  • 打开百度网站建设seo工具在线访问
  • 服务器可以备案别人的域名吗合肥网站seo
  • 东莞网站托管如何进行新产品的推广
  • 向搜索引擎提交网站营销型网站建设费用
  • 手机泉州网seo常见优化技术
  • 网站与网站做外链好吗seo优化网站推广全域营销获客公司
  • 如何提升网站的搜索排名平台app如何推广
  • 网站为什么要做seo开个网站平台要多少钱
  • 广州网站定制什么样的人适合做营销
  • 网站后台维护怎么做北京建站工作室
  • java新闻网站开发营销策略都有哪些方面
  • 网站开发测试工程师网络营销企业网站优化
  • 郑州市城乡建设局官网在线seo关键词排名优化
  • 网页制作怎么做多个网站杭州网站优化搜索
  • 古董做推广哪个网站好如何推广品牌知名度
  • 游戏是怎么做的视频网站百度推广怎么收费标准