Countto
组件类型:UxCounttoComponentPublicInstance
支持设置滚动时间,可显示小数
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
theme | String | info | 主题 |
startVal | Number | 0 | 开始的数值 |
endVal | Number | 0 | 要滚动的目标数值 |
duration | Number | 2000 | 滚动到目标数值的动画持续时间,单位为毫秒(ms) |
autoplay | Boolean | true | 设置数值后是否自动开始滚动 |
decimals | Number | 0 | 要显示的小数位数 |
format | String | 格式化规则 | |
color | String | $ux.Conf.fontColor | 字体颜色 |
darkColor | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
size | Any | $ux.Conf.fontSize | 字体大小 |
bold | Boolean | false | 字体是否加粗 |
margin | Array | 边距[上右下左][上下左右][上下左右] | |
mt | Any | 距上单位px | |
mr | Any | 距右单位px | |
mb | Any | 距下单位px | |
ml | Any | 距左单位px | |
padding | Array | 填充[上右下左][上下左右][上下左右] | |
pt | Any | 上内边距单位px | |
pr | Any | 右内边距单位px | |
pb | Any | 下内边距单位px | |
pl | Any | 左内边距单位px | |
xstyle | Array | 自定义样式 |
theme
值 | 说明 |
---|---|
text | 文字 |
info | 默认 |
primary | 主要 |
success | 成功 |
warning | 警告 |
error | 错误 |
format
值 | 说明 |
---|---|
cmoney大写金额 | |
qmoney金额千分制 | |
wmoney金额万分制 |
darkColor
值 | 说明 |
---|---|
none不显示 | |
auto自动适配深色模式 | |
color其他颜色 |
Events
事件名 | 说明 | 参数 |
---|---|---|
end | 数值滚动到目标值时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="数字滚动" :bold="true">
<ux-text text="支持设置滚动时间,可显示小数"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="主题" :bold="true">
<ux-text text="多种主题可配置,适配暗黑模式" :mb="15"></ux-text>
<ux-row>
<ux-countto theme="success" :startVal="0" :endVal="5000" :duration="2000"></ux-countto>
<ux-countto theme="warning" :startVal="0" :endVal="5000" :duration="2000" :ml="10"></ux-countto>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="小数" :bold="true">
<ux-text text="支持小数显示,可精确小数位数" :mb="15"></ux-text>
<ux-row>
<ux-countto theme="success" :decimals="2"></ux-countto>
<ux-countto theme="warning" :decimals="4" :ml="10"></ux-countto>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="格式化" :bold="true">
<ux-text text="支持格式化显示" :mb="15"></ux-text>
<ux-col>
<ux-countto theme="success" format="cmoney" :startVal="0" :endVal="5000" :duration="2000"></ux-countto>
<ux-countto theme="warning" format="qmoney" :startVal="0" :endVal="5000" :duration="1000" :mt="10"></ux-countto>
<ux-countto theme="error" format="wmoney" :startVal="0" :endVal="100000" :duration="10000" :mt="10"></ux-countto>
</ux-col>
</ux-card>
<ux-card direction="column" icon="arrowright" title="自由控制" :bold="true">
<ux-text text="支持控制动画播放" :mb="15"></ux-text>
<ux-col>
<ux-countto ref="uxCounttoRef" :autoplay="false"></ux-countto>
<ux-button theme="primary" :mt="10" text="开始" @click="start"></ux-button>
<ux-button theme="success" :mt="10" text="暂停" @click="pause"></ux-button>
<ux-button theme="warning" :mt="10" text="继续" @click="resume"></ux-button>
<ux-button theme="error" :mt="10" text="停止" @click="stop"></ux-button>
</ux-col>
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="数字滚动" :bold="true">
<ux-text text="支持设置滚动时间,可显示小数"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="主题" :bold="true">
<ux-text text="多种主题可配置,适配暗黑模式" :mb="15"></ux-text>
<ux-row>
<ux-countto theme="success" :startVal="0" :endVal="5000" :duration="2000"></ux-countto>
<ux-countto theme="warning" :startVal="0" :endVal="5000" :duration="2000" :ml="10"></ux-countto>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="小数" :bold="true">
<ux-text text="支持小数显示,可精确小数位数" :mb="15"></ux-text>
<ux-row>
<ux-countto theme="success" :decimals="2"></ux-countto>
<ux-countto theme="warning" :decimals="4" :ml="10"></ux-countto>
</ux-row>
</ux-card>
<ux-card direction="column" icon="arrowright" title="格式化" :bold="true">
<ux-text text="支持格式化显示" :mb="15"></ux-text>
<ux-col>
<ux-countto theme="success" format="cmoney" :startVal="0" :endVal="5000" :duration="2000"></ux-countto>
<ux-countto theme="warning" format="qmoney" :startVal="0" :endVal="5000" :duration="1000" :mt="10"></ux-countto>
<ux-countto theme="error" format="wmoney" :startVal="0" :endVal="100000" :duration="10000" :mt="10"></ux-countto>
</ux-col>
</ux-card>
<ux-card direction="column" icon="arrowright" title="自由控制" :bold="true">
<ux-text text="支持控制动画播放" :mb="15"></ux-text>
<ux-col>
<ux-countto ref="uxCounttoRef" :autoplay="false"></ux-countto>
<ux-button theme="primary" :mt="10" text="开始" @click="start"></ux-button>
<ux-button theme="success" :mt="10" text="暂停" @click="pause"></ux-button>
<ux-button theme="warning" :mt="10" text="继续" @click="resume"></ux-button>
<ux-button theme="error" :mt="10" text="停止" @click="stop"></ux-button>
</ux-col>
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>
ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const uxCounttoRef = ref<UxCounttoComponentPublicInstance | null>(null)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/countto.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e: OnLoadOptions) => {
title.value = e['title'] ?? ''
})
function start() {
uxCounttoRef.value!.start()
}
function pause() {
uxCounttoRef.value!.pause()
}
function resume() {
uxCounttoRef.value!.resume()
}
function stop() {
uxCounttoRef.value!.stop()
}
</script>
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const uxCounttoRef = ref<UxCounttoComponentPublicInstance | null>(null)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/countto.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e: OnLoadOptions) => {
title.value = e['title'] ?? ''
})
function start() {
uxCounttoRef.value!.start()
}
function pause() {
uxCounttoRef.value!.pause()
}
function resume() {
uxCounttoRef.value!.resume()
}
function stop() {
uxCounttoRef.value!.stop()
}
</script>
css
<style lang="scss">
</style>
<style lang="scss">
</style>