一 使用插件
vue3-danmaku
https://github.com/hellodigua/vue-danmaku/tree/vue3
npm install vue3-danmaku --save
做了一个简单demo
<template>
<div class="baberrage">
<vue-danmaku class="danmaku" ref="danmakuRef" v-model:danmus="danmus" useSlot loop :speeds="100" :channels="4">
<template v-slot:dm="{ danmu }">
<div class="danmaku-name">{{ danmu }}</div>
</template>
</vue-danmaku>
</div>
</template>
<script lang="ts" setup>
import vueDanmaku from 'vue3-danmaku'
import { ref } from 'vue'
const danmus = ref(['danmu1', 'danmu2', 'danmu3', 'danmu4', 'danmu5', 'danmu6', 'danmu7', 'danmu8'])
</script>
<style lang="less" scoped>
.baberrage {
width: 100%;
height: 400px;
background: rebeccapurple;
.danmaku {
width: 100%;
height: 100%;
&-name {
width: 150px;
height: 20px;
background: darkblue;
margin-right: 20px;
}
}
}
</style>