zoukankan      html  css  js  c++  java
  • react hooks数字滚动动画

    js:

    import { createElement, useRef } from 'rax';
    import View from 'rax-view';

    // css
    import './index.css';

    export default function Mod(props) {
    const list = ['7', '6', '0', '5', '3'];
    const textContainerRef = useRef();

    const NumUnit = (num, index) => {
      return (
        setTimeout(() => {
          const moveId = document.getElementById('move' + index);
          moveId.innerHTML = '';
          for (let i = 0; i <= num; i++) {
            moveId.innerHTML += `<Text style="color:red;">${i}</Text>`;
        }

          if (textContainerRef?.current) {
            let sum = 0;
            const height = textContainerRef.current.offsetHeight;
            setInterval(() => {
              if (height * num == height * (sum - 1)) return;
              moveId.style.marginTop = -(height * sum) + 'px';
              moveId.style.transition = '0.3s';
              sum += 1;
            }, 100)
          }
        }, 0)
      )
    }

    const ListView = () => {
      return (
        <View className="textBox">
        {
          list.map((item, index) => {
            return (
              <View className="textContainer" ref={textContainerRef}>
                <View id={'move' + index}>
                {
                  NumUnit(Number(item), index)
                }
                </View>
              </View>
            )
          })
        }
        </View>
      )
    };

    return (
      <View className="mod">
        <ListView />
      </View>
      );
    }
     
    css:
    .textBox{
      display: flex;
      flex-direction: row;
    }
    .textContainer{
       30rpx;
      height: 40rpx;
      border: 1rpx solid red;
      display: flex;
      align-items: center;
      line-height: 40rpx;
      overflow: hidden;
    }
  • 相关阅读:
    2015年个人记录
    Win10如何新建用户怎么添加新账户
    快速搭建一个本地的FTP服务器
    天气接口
    一张图搞定OAuth2.0
    PHP TS 和 NTS 版本选择
    如何在 Laravel 中使用 SMTP 发送邮件(适用于 163、QQ、Gmail 等)
    Npm vs Yarn 之备忘详单
    浅谈CSRF
    值得看的cookie详解
  • 原文地址:https://www.cnblogs.com/sunyang-001/p/15393574.html
Copyright © 2011-2022 走看看