微信小程序数字滚动效果

效果图

.wxml

复制代码
<view class="container">
    <view class="container-num" wx:for="{{number}}" wx:key="index">
    <view class="num-container" style="--h:{{h}}px;--y:{{-item * h }}px;">
      <view wx:for="{{10}}" wx:key="index" class="num-item">
        {{index}}
      </view>
    </view>
  </view>
</view>
<button bind:tap="getRandomNum">生成随机数</button>

.js

复制代码
Page({
  data: {
    number:'0',
    h:30,
  },
  getRandomNum(){
    const num = `${Math.floor(Math.random() * 1000)}`;
    this.setData({
      number:num
    })
  }
})

.wxss

复制代码
.container{
  padding: 100rpx 0;
  display: flex;
  justify-content: center;
}
.container-num{
  overflow: hidden;
}
.num-container{
  height: var(--h);
  transform:translateY(var(--y));
  transition-duration: 1s;
  margin: 0 1px;
}
.num-item{
  height: var(--h);
  flex-direction: column;
  display: flex;
  align-items: center;
  justify-content: center;
}

遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

相关推荐
HWL56799 小时前
显示器缩放和更改分辨率的区别
前端·css·vue.js·计算机外设·html5
沉默-_-10 小时前
微信小程序网络请求 wx.request 详解
网络·学习·微信小程序·小程序
沉默-_-12 小时前
微信小程序页面配置详解
学习·微信小程序·apache·微信开发者工具
鄭郑15 小时前
【Playwright 学习笔记 03】CSS选择器 定位方法
css·笔记·学习·playwright
EEEzhenliang16 小时前
CSS的注释
前端·css
幻影星空VR元宇宙17 小时前
飞行影院投资成本详解:球幕影院投资多少能实现盈利
css·百慕大冒险·幻影星空
_OP_CHEN17 小时前
【前端开发之HTML】(四)HTML 标签进阶:表格、表单、布局全掌握,从新手到实战高手!
前端·javascript·css·html·html5·网页开发·html标签
逆龙泰氽18 小时前
微信小程序开发04-1(小程序API)
微信小程序·小程序
少莫千华18 小时前
【HTML】CSS绘制奥运五环
前端·css·html
苏苏哇哈哈19 小时前
微信小程序实现高性能动态配置水滴凹槽、凸起Tabbar 组件
微信小程序·小程序