当前位置: 首页 > news >正文

如何查询网站备案号移动端cpu天梯图2021

如何查询网站备案号,移动端cpu天梯图2021,e网站建设,网页游戏服务端简介 本文将会基于react实现滚动菜单栏功能。 技术实现 实现效果 点击菜单,内容区域会自动滚动到对应卡片。内容区域滑动,指定菜单栏会被选中。 ScrollMenu.js import {useRef, useState} from "react"; import ./ScrollMenu.css;export co…

简介

        本文将会基于react实现滚动菜单栏功能。

技术实现

实现效果

       点击菜单,内容区域会自动滚动到对应卡片。内容区域滑动,指定菜单栏会被选中。

ScrollMenu.js
import {useRef, useState} from "react";
import './ScrollMenu.css';export const ScrollMenu = ({products}) => {// 获取 categoryProductMapconst categoryProductMap = new Map();products.forEach(product => {const category = product.category;let categoryProductList = categoryProductMap.get(category);if (!categoryProductList) {categoryProductList = [];}categoryProductList.push(product);categoryProductMap.set(category, categoryProductList);});// 获取类别列表const categoryList = Array.from(categoryProductMap.keys());// 菜单选中索引const [current, setCurrent] = useState(0);/*** 内容引用*/const contentRef = useRef();/*** 当左侧菜单点击时候*/const onMenuClick = (idx) => {if (idx !== current) {// 内容自动滚动到对应菜单位置contentRef.current.scrollTop = height.slice(0, idx).reduce((a, b) => a + b, 0);setCurrent(idx);}}/***  计算右侧商品类别卡片高度*/const height = [];const itemHeight = 25;categoryList.forEach((category, index) => {var productCnt = categoryProductMap.get(category).length;height.push((productCnt + 1) * itemHeight); // 0.8 是header高度});console.log(height)/*** 当右侧内容滚动时候*/const onContentScroll = () => {const scrollTop = contentRef.current.scrollTop;if (current < height.length - 1){const nextIdx = current + 1;// 计算下一个位置高度const nextHeight = height.slice(0, nextIdx).reduce((a, b) => a + b, 0);console.log('scrollTop', scrollTop, 'nextHeight', nextHeight, 'nextIdx', nextIdx)if (scrollTop >= nextHeight) {contentRef.current.scrollTop = nextHeight;setCurrent(nextIdx);return;}}if (current > 0) {const lastIdx = current - 1;// 计算上一个位置高度const lastHeight = height.slice(0, lastIdx).reduce((a, b) => a + b, 0);console.log('scrollTop', scrollTop, 'lastHeight', lastHeight, 'lastIdx', lastIdx)if (scrollTop <= lastHeight) {contentRef.current.scrollTop = lastHeight;setCurrent(lastIdx);return;}}}return (<div className='scroll-menu'><div className='menu'>{// 菜单列表categoryList.map((category, index) => {return (<div className={"menu-item" + ((index === current )? '-active' : '')}key={`${index}`} id={`menu-item-${index}`}onClick={(event) => {onMenuClick(index)}}>{category}</div>)})}</div><div className='content' ref={contentRef} onScroll={(event) => {onContentScroll()}}>{categoryList.map((category, index) => {// 获取类别商品const productList = categoryProductMap.get(category);return (<div key={index}><div className='content-item-header' key={`${index}`}id={`content-item-${index}`} style={{height: itemHeight}} >{category}</div>{productList.map((product,idx) => {return <div className='content-item-product'style={{height: itemHeight}}  key={`${index}-${idx}`} >{product.name}</div>})}</div>)})}</div></div>)
}
ScrollMenu.css
.scroll-menu {display: flex;flex-direction: row;width: 300px;height: 100px;
}.menu{width: 90px;height: 100px;display: flex;flex-direction: column;
}.menu-item {text-align: center;vertical-align: middle;}.menu-item-active {text-align: center;vertical-align: middle;background-color: lightcoral;
}.content {width: 210px;overflow: auto;
}.content-item-header{text-align: left;vertical-align: top;background-color: lightblue;
}.content-item-product{text-align: center;vertical-align: center;background-color: lightyellow;
}
App.js
import './App.css';
import {ScrollMenu} from "./component/scroll-menu/ScrollMenu";const App = ()=> {const products = [{category:'蔬菜',name:'辣椒'},{category:'蔬菜',name:'毛豆'},{category:'蔬菜',name:'芹菜'},{category:'蔬菜',name:'青菜'},{category:'水果',name:'苹果'},{category:'水果',name:'梨'},{category:'水果',name:'橘子'},   {category:'食物',name:'肉'},   {category:'食物',name:'罐頭'},   {category:'食物',name:'雞腿'}];return (<ScrollMenu products={products}/>)
}export default App;

http://www.yayakq.cn/news/516179/

相关文章:

  • 淄博网站建设专家发稿类别是什么
  • 定州网站建设巩义专业网站建设价格
  • 犀牛云做网站做网站需要多钱外包活加工官方网站
  • 网站服务器免费吗高埗镇网站建设公司
  • 免费域名申请 freenom最新seo兼职58
  • 个人社区网站备案全网营销
  • 网站域名找回密码 用户名wordpress锚文字
  • html电商网页制作广州网站建设十年乐云seo
  • 如何介绍设计的网站模板雍鑫建设集团网站
  • h5网站建设公司潍坊做网站的电话
  • 搜狗网站排名软件网站开发需要什么步骤
  • html代码图片十堰seo排名
  • 如何建个人网站教程wordpress的多说美化
  • 贵阳专业网站制作wordpress识图搜索代码6
  • ppt做的好的网站有哪些企业信息系统是什么
  • 网站内容收费建设银行网站注册企业
  • 网站建设需要哪些企业资料深圳设计家官网
  • 手机网站大全网址大全网站敏感目录漏洞修复
  • 广东网站建设包括什么第一网站ppt模板免费下载
  • 优秀网站建设方案男子替人做网站网站
  • 保定免费建站服务郑州网络推广哪家实力强
  • 网站规划html优秀网站制作实例展示
  • 东莞的网站建设建设厅八大员报名网站
  • 页面模板设计优化网站工具
  • tplink虚拟服务器做网站陕西省建设工会网站
  • 电视云网站建设数字营销技术应用
  • 品牌网站建设特色大蝌蚪上海好的网站设计公司
  • 网站建设的财务分析wordpress当地时间
  • 安防网站模板做cpa网站
  • 建站程序下载今天31个省新增最新消息视频讲解