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

.net网站开发技术简介wordpress接口

.net网站开发技术简介,wordpress接口,免费咨询法律顾问,wordpress 社交插件简介 本文将会基于react实现滚动菜单栏功能。 技术实现 实现效果 点击菜单#xff0c;内容区域会自动滚动到对应卡片。内容区域滑动#xff0c;指定菜单栏会被选中。 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 classNamescroll-menudiv classNamemenu{// 菜单列表categoryList.map((category, index) {return (div className{menu-item ((index current )? -active : )}key{${index}} id{menu-item-${index}}onClick{(event) {onMenuClick(index)}}{category}/div)})}/divdiv classNamecontent ref{contentRef} onScroll{(event) {onContentScroll()}}{categoryList.map((category, index) {// 获取类别商品const productList categoryProductMap.get(category);return (div key{index}div classNamecontent-item-header key{${index}}id{content-item-${index}} style{{height: itemHeight}} {category}/div{productList.map((product,idx) {return div classNamecontent-item-productstyle{{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.hkea.cn/news/14512741/

相关文章:

  • 刚做的网站关键词就上来了一级消防工程师考试题库及答案
  • 南京俄语网站建设百度推广的渠道有哪些
  • 国内较好的网站设计公司广西网络电视
  • 做数学题的网站网络推广图片大全
  • 公司网站设计图公司网站如何上传图片
  • 商城网站续费要多少钱网站关键词百度排名在下降
  • 网站开发流程进度规划最新装修设计效果图大全
  • 阿里云服务器做网站好用吗天津网站建设信息科技有限公司
  • 昌邑做网站网站改版协议
  • 哪里可以做网站的wordpress如何添加前台登录
  • 重庆网站自己推广承德网站开发区地税
  • 遵义网站开发的公司有哪些网站你懂我意思正能量免费软件
  • 学做网站论坛 可以吗网站建设海淀区
  • wordpress外贸网站建站教程wordpress内核源码
  • 羊 东莞网站开发百度大全
  • 昆明建网站要多少钱购物网站图片的放大怎么做的
  • 设计网站需要用到哪些技术宁波网站营销推广制作
  • 网站设计深圳要联系方式吗?重庆平台网站建设企业
  • 资讯类响应式网站模板好看的html页面模板
  • 广东建设监理网站网站 验证码错误
  • 绍兴网站制作网站开发者密钥
  • 网站内部链接怎麽做微信h5制作小程序有哪些
  • 学习网页设计与制作的网站网站建设名片
  • 商务酒店网站建设做网站显示不同字体
  • 装饰行业网站建设做网站建设哪家公司好
  • 网站域名备案地址医院手机网站模板
  • 传奇合成版2合1雷霆版温州网站关键词排名优化
  • 工作室做网站网站开发的薪资是多少
  • 网站弹出信息怎么做的网推平台有哪些比较好
  • 制作网站软件都在什么公司qq空间登录