Skip to content

St3DText 组件

3D 文本组件

注意事项

该组件中文本的 3D 效果,是通过多层文本在 z 轴方向上位移实现的;

组件示例

示例中使用到的 St3DTiltContainer 组件的具体用法可以参考其说明文档

Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
Hello, World! 你好,世界!
示例区域背景颜色
content
color
fontSize
layerCnt
layerGap
shadow
shadowSize
base
baseWidth
baseColor
baseShadow
perspective
示例代码
vue

<script setup lang="ts">
  import {St3DText, St3DTiltContainer} from 'st-common-ui-vue3'
  import {ref} from 'vue'

  const bgColor = ref('#efefef')
  const content = ref('Hello, World! 你好,世界!')
  const color = ref('#fff')
  const fontSize = ref('3rem')
  const layerCnt = ref(20)
  const layerGap = ref(1.5)
  const shadow = ref(true)
  const shadowSize = ref('5px')
  const base = ref(true)
  const baseWidth = ref('10px')
  const baseColor = ref('#fb7299')
  const baseShadow = ref(true)
  const perspective = ref('1000px')
</script>

<template>
  <div style="height: 300px; border-radius: 1rem; overflow: hidden;" :style="{background: bgColor}">
    <St3DTiltContainer fullPageListening>
      <div
          style="width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; transform-style: preserve-3d">
        <St3DText
            :content="content"
            :color="color"
            :fontSize="fontSize"
            :layerCnt="layerCnt"
            :layerGap="layerGap"
            :shadow="shadow"
            :shadowSize="shadowSize"
            :base="base"
            :baseWidth="baseWidth"
            :baseColor="baseColor"
            :baseShadow="baseShadow"
            :perspective="perspective"
        />
      </div>
    </St3DTiltContainer>
  </div>
</template>

组件参数

参数名说明类型默认值
content文本内容,该组件参数为必填项string
color文本的颜色string'#fff'
fontSize文本字体大小,如果传递的参数值为数字,则其单位为像素 pxnumber | string'3rem'
lineHeight文本的行高,如果传递的参数值为数字,则其单位为像素 px,如果向该参数传值,则文本的行高值于文本的字体大小相同number | stringundefined
layerCnt组成 3D 文本效果的文本层数number20
layerGap组件 3D 文本效果的文本层数每层之间的间距,其单位为像素 pxnumber1.5
shadow是否开启文本的阴影效果booleantrue
shadowSize文本阴影的大小,如果传递的参数值为数字,则其单位为像素 pxnumber | string'5px'
base是否开启 3D 文本的底层底座效果booleantrue
baseWidth3D 文本的底层底座的宽度,如果传递的参数值为数字,则其单位为像素 pxnumber | string'10px'
baseColor3D 文本的底层底座的颜色string'#fb7299'
baseShadow是否开启 3D 文本底座的阴影效果booleantrue
perspective3D 透视效果的距离,即观察者与 z=0 平面的距离,如果传递的参数值为数字,则其单位为像素 pxnumber | string'1000px'