/*! For license information please see 4315.9928acdc.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["4315"],{77597:function(s,n,t){"use strict";t.r(n);var a=t("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

RollingText

\n

Introduction

\n

Rolling text animation, which can roll numbers and other types of text. Please upgrade vant to >= v4.6.0 before using this component.

\n

Install

\n

Register component globally via app.use, refer to Component Registration for more registration ways.

\n
import { createApp } from 'vue';\nimport { RollingText } from 'vant';\n\nconst app = createApp();\napp.use(RollingText);\n
\n

Usage

\n

Basic Usage

\n

You can set the starting value with start-num and the target value with target-num. The RollingText component will automatically start the animation, rolling from the starting value to the target value.

\n
<van-rolling-text :start-num="0" :target-num="123" />\n
\n

Set Rolling Direction

\n

You can set the rolling direction of the numbers using the direction prop. By default, it rolls downwards, but you can set it to up to roll upwards.

\n
<van-rolling-text :start-num="0" :target-num="432" direction="up" />\n
\n

Set Stop Order

\n

You can set the order of stopping the animation of each digit through the stop-order prop. By default, it stops from the higher digits. Setting rtl can stop from the ones digit.

\n
<van-rolling-text :start-num="0" :target-num="54321" stop-order="rtl" />\n
\n

Roll Non-numeric Text

\n

You can reverse non-numeric content by using the text-list prop. The component will rolling from the first item to the last item in the array. Please make sure that the array length is greater than or equal to 2, and that each item has the same length.

\n
<van-rolling-text :text-list="textList" :duration="1" />\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const textList = ref([\n      'aaaaa',\n      'bbbbb',\n      'ccccc',\n      'ddddd',\n      'eeeee',\n      'fffff',\n      'ggggg',\n    ]);\n    return { textList };\n  },\n};\n
\n

Custom Style

\n

The RollingText component provides some CSS variables that you can override to customize the style, or you can directly modify the component\'s style. Additionally, you can set the height of the numbers using the height prop.

\n
<van-rolling-text\n  class="my-rolling-text"\n  :height="54"\n  :start-num="12345"\n  :target-num="54321"\n/>\n
\n
.my-rolling-text {\n  --van-rolling-text-background: #1989fa;\n  --van-rolling-text-color: white;\n  --van-rolling-text-font-size: 24px;\n  --van-rolling-text-gap: 6px;\n  --van-rolling-text-item-border-radius: 5px;\n  --van-rolling-text-item-width: 40px;\n}\n
\n

Manual Control

\n

After obtaining the component instance through ref, you can call the start and reset methods. The start method is used to start the animation, and the reset method is used to reset the animation.

\n
<van-rolling-text\n  ref="rollingTextRef"\n  :start-num="0"\n  :target-num="54321"\n  :auto-start="false"\n/>\n<van-grid clickable :column-num="3">\n  <van-grid-item icon="play-circle-o" :text="start" @click="start" />\n  <van-grid-item icon="replay" :text="reset" @click="reset" />\n</van-grid>\n
\n
import { ref } from 'vue';\n\nexport default {\n  setup() {\n    const rollingTextRef = ref(null);\n    const start = () => {\n      rollingTextRef.value.start();\n    };\n    const reset = () => {\n      rollingTextRef.value.reset();\n    };\n    return { rollingTextRef, start, reset };\n  },\n};\n
\n

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
start-numStart numbernumber0
target-numTarget numbernumber-
text-listText arraystring[][]
durationDuration of the animation, in secondsnumber2
directionRolling direction of the text, with down and up as the valuesstringdown
auto-startWhether to start the animationbooleantrue
stop-orderOrder of stopping the animation of each digit, with ltr and rtl as the valuesstringltr
heightHeight of digit, px as unitnumber40
\n

Methods

\n

Use ref to get RollingText instance and call instance methods.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDescriptionAttributeReturn value
startStart the animation--
resetReset the animation--
\n

Types

\n

The component exports the following type definitions:

\n
import type {\n  RollingTextProps,\n  RollingTextInstance,\n  RollingTextDirection,\n  RollingTextStopOrder,\n} from 'vant';\n
\n

RollingTextInstance is the type of component instance:

\n
import { ref } from 'vue';\nimport type { RollingTextInstance } from 'vant';\n\nconst rollingTextRef = ref<RollingTextInstance>();\n\nrollingTextRef.value?.start();\n
\n

Theming

\n

CSS Variables

\n

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDefault ValueDescription
--van-rolling-text-backgroundinheritBackground color of a single digit
--van-rolling-text-colorvar(--van-text-color)Color of the number
--van-rolling-text-font-sizevar(--van-font-size-md)Font size of the number
--van-rolling-text-gap0pxSpacing between digits
--van-rolling-text-item-width15pxWidth of a single digit
--van-rolling-text-item-border-radius0pxBorder radius of a single digit
\n
'},null,8,e))}}}]);