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

做网站网址营销软文范文

做网站网址,营销软文范文,导航网站的网站地图怎么做,没有服务器怎么做网站简介 本文将会基于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.tj-hxxt.cn/news/10684.html

相关文章:

  • 专业网站建设公司哪个公司好男生最喜欢的浏览器
  • 移动端网站制作的有哪些要求网站建设服务
  • 网站分为哪几种如何做一个自己的网页
  • 3g下订单的网站怎么做西安企业seo外包服务公司
  • 图文网站源码培训心得体会300字
  • 厦门靠谱建网站公司seo点击排名软件哪家好
  • 天津网站建设哪家好在线培训app
  • 高端别墅装饰设计公司泰州网站排名seo
  • 服装 网站规划方案免费推广网站平台
  • 建设网站开发方案百度优化是什么
  • 凡客网上做的网站能否更改域名免费网络空间搜索引擎
  • 贵阳网站建设公司招聘建站平台哪个好
  • wordpress完全卸载教程seo搜索优化邵阳
  • 网站编排类型品牌线上推广方案
  • 上海网站建设公司费用优化教程网
  • 个体户做网站去哪里做百度推广费用一年多少钱
  • 网站模板安卓网站统计系统
  • 如何做免费的网站推广开发网站建设
  • 项目网站开发js放的位置企业高管培训课程有哪些
  • wordpress 仿neoeaaeseo人人网
  • 外贸soho网站建设真实的网站制作
  • 网站建设基础百度百科搜狗网页搜索
  • 曲靖网站微信建设微信营销典型案例
  • 视频直播系统源码福州网站优化公司
  • 外包做的网站可以直接去收录吗中山360推广
  • 专门做甜点的视频网站网站超级外链
  • 惠州做网站 百度优化一键关键词优化
  • 国外儿童社区网站模板软文外链代发
  • 网站里的内容都是什么作用如何在百度上发广告
  • 网站建设 上海网站建如何开展网络营销