Vue3实现打字机效果
vue
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
项目地址:https://gitcode.com/gh_mirrors/vu/vue
免费下载资源
·
typeit 介绍
typeit
是一款轻量级打字机特效插件。该打印机特效可以设置打字速度,是否显示光标,是否换行和延迟时间等属性,它可以打印单行文本和多行文本,并具有可缩放、响应式等特点。官方文档
安装
# npm
npm install typeit
# pnpm
pnpm add typeit
代码
<template>
<span ref="text" class="msg"></span>
</template>
<script setup>
// https://www.typeitjs.com/docs/vanilla/usage/#configuration-basics
// npm install typeit
import { ref, onMounted } from "vue";
import TypeIt from 'typeit'
const text = ref(null)
onMounted(() => {
new (TypeIt)(text.value, {
strings: ["你好", "欢迎", "测试测试测试"],
cursorChar: "<span class='cursorChar'>|<span>",//用于光标的字符。HTML也可以
speed: 100,
lifeLike: true,// 使打字速度不规则
cursor: true,//在字符串末尾显示闪烁的光标
breakLines: false,// 控制是将多个字符串打印在彼此之上,还是删除这些字符串并相互替换
loop: true,//是否循环
}).go()
})
</script>
<style scoped>
.msg {
color: rgb(88, 88, 88);
letter-spacing: 2px;
}
.msg :v-deep(.cursorChar){
display: inline-block;
margin-left: 2px;
}
</style>
封装为组件
<template>
<span ref="text" class="msg"></span>
</template>
<script setup>
/**
* 打字机效果
* npm install typeit
* https://www.typeitjs.com/docs/vanilla/usage/#configuration-basics
*/
import { ref, onMounted } from "vue";
import TypeIt from 'typeit'
const props = defineProps({ strings: { type:Array } })
const text = ref(null)
onMounted(() => {
new (TypeIt)(text.value, {
strings: props.text,
cursorChar: "<span class='cursorChar'>|<span>",//用于光标的字符。HTML也可以
speed: 150,
lifeLike: true,// 使打字速度不规则
cursor: true,//在字符串末尾显示闪烁的光标
breakLines: false,// 控制是将多个字符串打印在彼此之上,还是删除这些字符串并相互替换
loop: true,//是否循环
}).go()
})
</script>
<style lang='scss' scoped>
.msg {
color: var(--el-color-info-light-3);
letter-spacing: 2px;
:v-deep(.cursorChar) {
display: inline-block;
margin-left: 2px;
}
}
</style>
GitHub 加速计划 / vu / vue
207.52 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:1 个月前 )
73486cb5
* chore: fix link broken
Signed-off-by: snoppy <michaleli@foxmail.com>
* Update packages/template-compiler/README.md [skip ci]
---------
Signed-off-by: snoppy <michaleli@foxmail.com>
Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 3 个月前
e428d891
Updated Browser Compatibility reference. The previous currently returns HTTP 404. 3 个月前
更多推荐
已为社区贡献2条内容
所有评论(0)