实例|APICloud AVM框架打造数字滚动组件

简介: 数字滚动组件,用于数字的动态效果展示。今天用APICloud AVM框架打造数字滚动组件。

数字滚动组件,用于数字的动态效果展示。今天用APICloud AVM框架打造数字滚动组件。


组件中用到的核心功能点是,background-position属性设置背景图像的起始位置。每个数字占位的背景图片是一个0-9数字组成的图片,通过随机产生不同的图片其实位置来展示不同的数字。


通过延迟产生每次的位置,来控制数字切换的频率,这个是可以自定义的。


可自定义数字其实位置,靠左,靠右,居中。


可自定义展示的数字个数。


组件文件

count-up.stml


<template>

<view class="easy-count-up_container">

<view class="easy-count-up_img" :style="justifyStyle">

<view class="easy-count-up_img-item" :style="item" v-for="item in roundStyle">

</view>

</view>

</view>

</template>

<script>

export default {

name: 'easy-count-up',

props:{

during:Number,

customNum:Number,

justify:String

},

install(){

for (let index = 0; index < this.props.customNum; index++) {

this.data.roundStyle[index]='background-position: 0px 0px;';

}

if(this.props.justify=='left'){

this.data.justifyStyle='justify-content: flex-start;';

}

else if(this.props.justify=='right'){

this.data.justifyStyle='justify-content: flex-end;';

}

},

installed(){

let timer = null;

timer = setInterval(() => {

for (let index = 0; index < this.data.roundStyle.length; index++) {

this.data.roundStyle[index]='background-position: 0px -'+ Math.floor( Math.random()*10 )*58 +'px;';

}

},this.props.during?this.props.during:5000)

},

data() {

return{

customNumber:0,

roundStyle:[],

justifyStyle:'justify-content: center;'

}

},

methods: {

 

}

}

</script>

<style>

.easy-count-up_container{

width: 100%;

padding: 5px;

background-color: #ffffff;

}

.easy-count-up_img{

height: 47px;

flex-flow: row nowrap;

}

.easy-count-up_img-item{

width: 33px;

height: 47px;

margin-right: 5px;

background-image: url(https://img10.360buyimg.com/imagetools/jfs/t1/133024/3/2251/2646/5ee7549aE8dc02d7e/de6901b6c72db396.png);

transition: all 800ms ease 0s;

background-repeat: no-repeat;

}

</style>

组件使用

demo-count-up.stml


<template>

<view class="page">

<safe-area></safe-area>

<text>随机抽取{customNum}位数的号码牌</text>

<easy-count-up

:during="during"

:customNum="customNum"

:justify="justify"

></easy-count-up>

<text>随机抽取{customNum1}位数的号码牌</text>

<easy-count-up

:during="during1"

:customNum="customNum1"

:justify="justify1"

></easy-count-up>

<text>随机抽取{customNum2}位数的号码牌</text>

<easy-count-up

:customNum="customNum2"

:justify="justify2"

></easy-count-up>

</view>

</template>

<script>

import '../../components/easy-count-up.stml'

export default {

name: 'demo-easy-count-up',

apiready(){//like created

 

},

data() {

return{

during:2000,//数字滚动一次的时间 单位毫秒

customNum:6,//数字的个数

justify:'center',//号码数字位置 center,left,right

during1:5000,//数字滚动一次的时间 单位毫秒

customNum1:3,//数字的个数

justify1:'left',//号码数字位置 center,left,right

 

during2:3000,//数字滚动一次的时间 单位毫秒

customNum2:5,//数字的个数

justify2:'right',//号码数字位置 center,left,right

}

},

methods: {

}

}

</script>

<style>

.page {

height: 100%;

background-color: #f0f0f0;

justify-content: flex-start;

align-items: center;

}



目录
相关文章
|
2天前
|
JavaScript
vue + element UI【实战】音乐播放器/语音条(内含音频的加载、控制,事件监听,信息获取,手机网页阴影的去除等技巧)
vue + element UI【实战】音乐播放器/语音条(内含音频的加载、控制,事件监听,信息获取,手机网页阴影的去除等技巧)
6 1
|
7月前
|
JSON 小程序 JavaScript
|
1天前
|
小程序 JavaScript 前端开发
【微信小程序-原生开发】实用教程06-轮播图、分类页签 tab 、成员列表(含Tdesign升级,切换调试基础库,设置全局样式,配置组件按需注入,添加图片素材,wx:for,生命周期 onLoad)
【微信小程序-原生开发】实用教程06-轮播图、分类页签 tab 、成员列表(含Tdesign升级,切换调试基础库,设置全局样式,配置组件按需注入,添加图片素材,wx:for,生命周期 onLoad)
5 0
|
8月前
|
小程序 开发者
wepy框架-触摸内容滑动组件使用步骤
wepy框架-触摸内容滑动组件使用步骤
30 0
|
11月前
|
前端开发
【React工作记录九十】ant design table实现上下行拖拽功能(类组件)
【React工作记录九十】ant design table实现上下行拖拽功能(类组件)
155 0
|
前端开发
#yyds干货盘点 ant design table实现上下行拖拽功能(类组件)
#yyds干货盘点 ant design table实现上下行拖拽功能(类组件)
160 0
|
JavaScript 前端开发 小程序
APICloud AVM框架 纵向滚动通知栏组件
用于循环播放展示一组消息通知,实现了纵向滚动。
APICloud AVM框架 纵向滚动通知栏组件
|
移动开发 开发工具 git
关于ReactNative0.56版本Flatlist列表内容跳动的问题
关于ReactNative0.56版本Flatlist列表内容跳动的问题
163 0
关于ReactNative0.56版本Flatlist列表内容跳动的问题
|
新能源
APICloud AVM框架封装车牌号输入键盘组件
APICloud AVM框架 封装车牌号输入键盘组件实例分享。封装了车牌号输入键盘,支持燃油汽车、新能源车辆、教练车、挂车、警车5种模式。针对输入的车牌号进行了正则验证。
115 0
|
前端开发
实例|APICloud AVM框架封装滑动单元格组件
滑动单元格组件原理是主题部分把按钮进行遮挡,按钮通过绝对定位,定位在最右边,通过监听触摸事件(touch),判断滑动的方向和计算滑动的距离以此来判定显示和隐藏按钮。
159 0

热门文章

最新文章