react 使用react-seamless-scroll实现无缝滚动

1. 实现无缝滚动效果

  1. 实现单步向下滚动
  2. 点击更多展开,收起,调整 scroll 高度

请添加图片描述

2. react-seamless-scroll 无缝滚动案例介绍

  1. 项目地址 react-seamless-scroll
  2. 拉下来跑起来效果(gif录屏有点卡,实际很丝滑)
    请添加图片描述
  3. 可以支持多种无缝滚动方案,如 向下滚动向左滚动滚动速度鼠标悬停单布停顿单行停顿时间数组属性更新数组添加数据图表滚动
  4. react-seamless-scroll 无缝滚动有两种实现方式,一种是 cssSeamlessScroll,另外一种是 jsSeamlessScroll

3. react 项目集成

3.1 项目引入 cssSeamlessScroll 滚动组件

1.这里我使用的 cssSeamlessScroll 的。
2. 将 cssSeamlessScroll 组件 的代码复制到项目中

在这里插入图片描述

3.2 完整代码

3.2.1 newBet.tsx 代码

import React, {
    useState } from 'react';
import style from '../style/index.module.scss';
// 导入滚动的cssSeamlessScroll
import CssSeamlessScroll from './cssSeamlessScroll/cssSeamlessScroll'

const NewBet = () => {
   
    const [height, setHeight] = useState(320);
    // mock 后端返回数据
    const [arr, setArr] = useState([
        {
    gameName: '象财神', player: 'Dorothy MurrayDorothy Murray', betAmount: 4020, profit: -476.53 },
        {
    gameName: '皇上吉祥', player: '隐身', betAmount: 4020, profit: 516.82 },
        {
    gameName: '水果丛林', player: 'Frederick Long', betAmount: 4020, profit: 809.59 },
        {
    gameName: '唐伯虎点秋香', player: '隐身', betAmount: 4020, profit: -928.13 },
        {
    gameName: '鼠鼠福福', player: 'Adele Moody', betAmount: 4020, profit: -901.85 },
        {
    gameName: '宝石侠-1111', player: 'Maggie Cobb', betAmount: 4020, profit: 135.91 },
        {
    gameName: '糖果连连爆', player: 'Jeremiah Harran', betAmount: 4020, profit: 960.88 },
        {
    gameName: '艳后之迷', player: 'Nellie Wong', betAmount: 4020, profit: 227.48 },
        {
    gameName: '象财神', player: 'Dorothy MurrayDorothy Murray', betAmount: 4020, profit: -476.53 },
        {
    gameName: '皇上吉祥', player: '隐身', betAmount: 4020, profit: 516.82 },
        {
    gameName: '水果丛林', player: 'Frederick Long', betAmount: 4020, profit: 809.59 },
        {
    gameName: '唐伯虎点秋香', player: '隐身', betAmount: 4020, profit: -928.13 },
        {
    gameName: '鼠鼠福福', player: 'Adele Moody', betAmount: 4020, profit: -901.85 },
        {
    gameName: '宝石侠-1111', player: 'Maggie Cobb', betAmount: 4020, profit: 135.91 },
        {
    gameName: '糖果连连爆', player: 'Jeremiah Harran', betAmount: 4020, profit: 960.88 },
        {
    gameName: '艳后之迷', player: 'Nellie Wong', betAmount: 4020, profit: 227.48 },
    ]);

    return (
        <div className={
   style.newBetContent}>
            <div className='px-3 text-white'>
                <div className={
   style.table}>
                    <div className={
   style.header}>
                        <span>游戏</span>
                        <span>玩家</span>
                        <span>投注</span>
                        <span>利润额</span>
                    </div>
                    <div className={
   style.scroll} style={
   {
    height: height + 'px' }}>
                        <CssSeamlessScroll datas={
   arr} direction="down" duration={
   20} step={
   16}>
                            {
   arr.map((_item, _index) => (
                                <div className={
   style.item}>
                                    <span><img className='h-5 mr-1' src={
   require('@/branch/assets/images/home/majorVictory/icon-gold.png')} />{
   _item.gameName}</span>
                                    <span>{
   _item.player}</span>
                                    <span>{
   _item.betAmount}</span>
                                    <span className={
   _item.profit > 0 ? style.green : style.red}>{
   _item.profit}<img className='h-3 ml-1' src={
   require('@/branch/assets/images/home/majorVictory/icon-gold.png')} /></span>
                                </div>
                            ))}
                        </CssSeamlessScroll>
                    </div>
                    <div className={
   style.moreBtn} onClick={
   () => {
   
                        setHeight(height == 320 ? 520 : 320)
                    }}>
                        <span>展示更多</span>
                        {
   
                            height == 320 ?
                                <img className='h-3 ml-2' src={
   require('@/branch/assets/images/sclog/bh.png')} /> :
                                <img className='h-3 ml-2' src={
   require('@/branch/assets/images/sclog/zk.png')} />
                        }
                    </div>
                </div>
            </div>
        </div>
    );
};
export default NewBet;

3.2.2 index.module.scss

.newBetContent {
   
    width: 100%;
    .table,
    .scroll {
   
        .header,
        .item {
   
            height: 40px;
            display: flex;
            align-items: center;
            color: #93acd3;
            font-size: 12px;
            span {
   
                text-align: left;
                img {
   
                    vertical-align: middle;
                }
                &:nth-child(1),
                &:nth-child(2) {
   
                    display: inline-block;
                    width: 103px;
                    white-space: nowrap; /* 强制内容在一行上显示,防止换行 */
                    overflow: hidden; /* 超出容器部分隐藏 */
                    text-overflow: ellipsis; /* 超出容器部分显示省略号 */
                }
                &:nth-child(2) {
   
                    text-align: center;
                    color: #fff;
                }
                &:nth-child(3) {
   
                    text-align: center;
                    display: inline-block;
                    width: 80px;
                    text-align: center;
                    color: #fff;
                }
                &:nth-child(4) {
   
                    display: inline-block;
                    width: 80px;
                    text-align: right;
                }
                &.green {
   
                    color: #3bc116;
                }
                &.red {
   
                    color: #f53202;
                }
            }
        }
        .header {
   
            height: 32px;
            line-height: 32px;
            span {
   
                &:nth-child(2),
                &:nth-child(3) {
   
                    color: #93acd3;
                }
            }
        }
    }
    .table {
   
        background: #161f2c;
        border-radius: 10px;
        padding: 0px 8px;
        text-align: center;
        .moreBtn {
   
            margin: 16px auto;
            display: inline-block;
            font-family: PingFang SC, PingFang SC-Regular;
            font-weight: Regular;
            text-align: left;
            line-height: 14px;
            background: #1e2837;
            border-radius: 10px;
            padding: 9px 12px;
            span {
   
                font-size: 14px;
                color: #93acd3;
            }
            img {
   
                margin-top: 1px;
            }
        }
    }
    .scroll {
   
        display: inline-block;
        width: 100%;
        overflow: hidden;
        position: relative;
        transition: height 0.5s ease;
    }
}

相关推荐

  1. vue3-seamless-scroll实现循环滚动

    2024-02-04 17:18:01       8 阅读
  2. vue大屏-列表自动滚动vue-seamless-scroll

    2024-02-04 17:18:01       39 阅读
  3. React实现虚拟加载滚动

    2024-02-04 17:18:01       30 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-04 17:18:01       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-04 17:18:01       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-04 17:18:01       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-04 17:18:01       18 阅读

热门阅读

  1. IdleHandler的简单认识

    2024-02-04 17:18:01       34 阅读
  2. 学习数据结构的第一天

    2024-02-04 17:18:01       31 阅读
  3. CSS基础

    CSS基础

    2024-02-04 17:18:01      25 阅读
  4. linux编译ffmpeg动态库

    2024-02-04 17:18:01       31 阅读
  5. 如何有效的开展接口自动化测试(超详细整理)

    2024-02-04 17:18:01       33 阅读
  6. Spring依赖注入原理与最佳实践

    2024-02-04 17:18:01       37 阅读
  7. Pinia:一个Vue的状态管理库

    2024-02-04 17:18:01       31 阅读
  8. 面试高频知识点:2线程 2.1.4 线程池常用参数

    2024-02-04 17:18:01       31 阅读