Countup 숫자 스크롤
Countup은 숫자가 굴러가듯 스크롤되는 효과를 보여주는 컴포넌트예요. 숫자가 변하는 모습을 동적으로 표현할 때 쓰죠.
출처: 문서
설치
@nutui/nutui에서 컴포넌트를 가져와 앱에 등록하면 바로 쓸 수 있어요.
import { createApp } from 'vue'
import { Countup } from '@nutui/nutui'
const app = createApp()
app.use(Countup)
사용 예시
기본 사용법
demo: countup basic
커스텀 스크롤 그림 표시
demo: countup custom
럭키 드로우(롤링 추첨 시뮬레이션)
demo: countup scroll
API
Props
| Attribute | Description | Type | Default |
|---|---|---|---|
| init-num | initial number | number | 0 |
| end-num | end number | number | 0 |
| speed | interval number, currently only supports basic usage | number | 1 |
| to-fixed | retain the number of decimal places | number | 0 |
| start-flag | flag to trigger number scrolling | boolean | true |
| during | rolling time to run | number | 1000 |
| num-width | Number width, often used to customize seamless scrolling | number | 20 |
| num-height | Number height, often used to customize seamless scrolling (required for lottery function) | number | 20 |
| custom-change-num | The number to change (for custom pictures, initNum and endNum are invalid here) | number | 1 |
| custom-bg-img | Custom image (it is recommended to use Sprite image, and Sprite image must be used to use the lottery function) | string | - |
| custom-spac-num | There may be space between numbers in the image | number | 0 |
| type | lottery function pass machine, the optional value is machine ' ' |
string | '' |
| machine-prize-num | Number of prizes, how many prizes in total, must be passed | number | 0 |
| machine-num | lottery position, that is, how many times to roll, must pass | number | 3 |
| machine-prize-level | The winning icon, the position of the icon in the sprite image | number | 0 |
| machine-turn-more | number of turns | number | 0 |
참고: 뽑기(lottery) 기능은 아이콘 위치와 함께 계산하기 때문에, 스프라이트 이미지 안 단일 아이콘의 높이
num-height를 반드시 넘겨야 해요. 당첨 상품은 스프라이트 이미지 안 상품 개수를 기준으로 1부터 N까지 위치를 잡아요.
Events
| Event | description | callback parameter |
|---|---|---|
| scroll-end | callback function after scrolling ends | - |
더 알아보기 (Learn more)
- 원문 문서: NutUI Countup 공식 문서(영문)
- NutUI는 JD.com이 공개한 Vue 3 모바일 컴포넌트 라이브러리예요. 전체 컴포넌트 목록은 공식 문서 사이트에서, 소스 코드는 GitHub 저장소에서 볼 수 있어요.