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

本文主要是介绍react 使用react-seamless-scroll实现无缝滚动,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 1. 实现无缝滚动效果
  • 2. react-seamless-scroll 无缝滚动案例介绍
  • 3. react 项目集成
    • 3.1 项目引入 `cssSeamlessScroll` 滚动组件
    • 3.2 完整代码
      • 3.2.1 newBet.tsx 代码
      • 3.2.2 index.module.scss

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;}
}

这篇关于react 使用react-seamless-scroll实现无缝滚动的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/676458

相关文章

SpringBoot集成redisson实现延时队列教程

《SpringBoot集成redisson实现延时队列教程》文章介绍了使用Redisson实现延迟队列的完整步骤,包括依赖导入、Redis配置、工具类封装、业务枚举定义、执行器实现、Bean创建、消费... 目录1、先给项目导入Redisson依赖2、配置redis3、创建 RedissonConfig 配

Python的Darts库实现时间序列预测

《Python的Darts库实现时间序列预测》Darts一个集统计、机器学习与深度学习模型于一体的Python时间序列预测库,本文主要介绍了Python的Darts库实现时间序列预测,感兴趣的可以了解... 目录目录一、什么是 Darts?二、安装与基本配置安装 Darts导入基础模块三、时间序列数据结构与

Python使用FastAPI实现大文件分片上传与断点续传功能

《Python使用FastAPI实现大文件分片上传与断点续传功能》大文件直传常遇到超时、网络抖动失败、失败后只能重传的问题,分片上传+断点续传可以把大文件拆成若干小块逐个上传,并在中断后从已完成分片继... 目录一、接口设计二、服务端实现(FastAPI)2.1 运行环境2.2 目录结构建议2.3 serv

C#实现千万数据秒级导入的代码

《C#实现千万数据秒级导入的代码》在实际开发中excel导入很常见,现代社会中很容易遇到大数据处理业务,所以本文我就给大家分享一下千万数据秒级导入怎么实现,文中有详细的代码示例供大家参考,需要的朋友可... 目录前言一、数据存储二、处理逻辑优化前代码处理逻辑优化后的代码总结前言在实际开发中excel导入很

Spring Security简介、使用与最佳实践

《SpringSecurity简介、使用与最佳实践》SpringSecurity是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架,本文给大家介绍SpringSec... 目录一、如何理解 Spring Security?—— 核心思想二、如何在 Java 项目中使用?——

SpringBoot+RustFS 实现文件切片极速上传的实例代码

《SpringBoot+RustFS实现文件切片极速上传的实例代码》本文介绍利用SpringBoot和RustFS构建高性能文件切片上传系统,实现大文件秒传、断点续传和分片上传等功能,具有一定的参考... 目录一、为什么选择 RustFS + SpringBoot?二、环境准备与部署2.1 安装 RustF

Nginx部署HTTP/3的实现步骤

《Nginx部署HTTP/3的实现步骤》本文介绍了在Nginx中部署HTTP/3的详细步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录前提条件第一步:安装必要的依赖库第二步:获取并构建 BoringSSL第三步:获取 Nginx

springboot中使用okhttp3的小结

《springboot中使用okhttp3的小结》OkHttp3是一个JavaHTTP客户端,可以处理各种请求类型,比如GET、POST、PUT等,并且支持高效的HTTP连接池、请求和响应缓存、以及异... 在 Spring Boot 项目中使用 OkHttp3 进行 HTTP 请求是一个高效且流行的方式。

MyBatis Plus实现时间字段自动填充的完整方案

《MyBatisPlus实现时间字段自动填充的完整方案》在日常开发中,我们经常需要记录数据的创建时间和更新时间,传统的做法是在每次插入或更新操作时手动设置这些时间字段,这种方式不仅繁琐,还容易遗漏,... 目录前言解决目标技术栈实现步骤1. 实体类注解配置2. 创建元数据处理器3. 服务层代码优化填充机制详

Python实现Excel批量样式修改器(附完整代码)

《Python实现Excel批量样式修改器(附完整代码)》这篇文章主要为大家详细介绍了如何使用Python实现一个Excel批量样式修改器,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一... 目录前言功能特性核心功能界面特性系统要求安装说明使用指南基本操作流程高级功能技术实现核心技术栈关键函