微信小程序数字滚动效果

效果图

.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,很少看博客,对你有帮助别忘记点赞收藏。

相关推荐
不如摸鱼去8 小时前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
微信小程序·小程序·uni-app·aigc·ai编程
讨厌吃蛋黄酥9 小时前
前端居中九种方式血泪史:面试官最爱问的送命题,我一次性整明白!
前端·css
意会10 小时前
微信闪照小程序实现
前端·css·微信小程序
码码哈哈爱分享11 小时前
Tauri 框架介绍
css·rust·vue·html
一枚前端小能手12 小时前
🎨 CSS布局从入门到放弃?Grid让你重新爱上布局
前端·css
落雪小轩韩13 小时前
网格布局 CSS Grid
前端·css
小白_ysf13 小时前
uniapp 开发微信小程序,获取经纬度并且转化详细地址(单独封装版本)
微信小程序·uni-app
睡不着先生15 小时前
`text-wrap: balance` 实战指南:让多行标题自动排版更优美
css
Wcy307651906616 小时前
web前端第二次作业
前端·javascript·css
waterHBO16 小时前
css 模拟一个动画效果,消息堆叠。
前端·css