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

Vue3实现打字机效果

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>
http://www.lryc.cn/news/64695.html

相关文章:

  • maven无法依赖spring-cloud-stater-zipkin如何解决?
  • 实战踩坑---MFC---CreateEvent
  • JavaWeb学习------jQuery
  • 米哈游测开岗 【一面总结】
  • 微服务 Spring Boot 整合Redis 实现优惠卷秒杀 一人一单
  • 构建OVS网络
  • 【Python】万能之王 Lambda 函数详解
  • 手把手教你怎么搭建自己的AI数字人直播间?帮你24小时不间断直播卖货
  • MySQL性能监控全掌握,快来get关键指标及采集方法!
  • sed进阶之保留空间和排除命令
  • 21安徽练习
  • 【VAR | 时间序列】应用VAR模型时的15个注意点
  • 校招在线测评题目汇总
  • 『python爬虫』05. requests模块入门(保姆级图文)
  • WPF超好用的框架Prism入门使用,上位机赶紧学起来!
  • 十个机器学习应用实例
  • 【Redis17】Redis进阶:管道
  • Django项目页面样式如何“传给”客户端浏览器
  • python 进程间通信 Queue()、Pipe()、manager.list()、manager.dict()、manager.Queue()
  • 你想要的【微前端】都在这里了! | 京东云技术团队
  • 人生若只如初见,你不来看看Django吗
  • 项目人力资源管理
  • 提供接口给第三方调用,应该注意什么
  • ESL设计概述
  • 探究C语言数组的奥秘:大小可省略的定义、内存存储、数组名、传参、指针遍历、数组指针和指针数组、柔性数组等
  • python3 强制使用任意父级相对导入,越过python相对导入限制,拒绝 ImportError
  • 面了一个4年经验的测试工程师,自动化都不会也要15k,我也是醉了····
  • Java 实现 YoloV7 人体姿态识别
  • 跨越屏幕:桌面PC端的多端开发框架介绍
  • 高效学习方法和工具推荐,让你事半功倍!