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

做网站网址搜索引擎营销是什么意思

做网站网址,搜索引擎营销是什么意思,苹果cms影视模板,属于水平b2b电商平台的模式有简介 本文将会基于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.ds6.com.cn/news/51335.html

相关文章:

  • 赣州市建设局建管科网站第三方网站流量统计
  • 微信怎么开店铺小程序福州seo网站推广优化
  • 自己可以做网站吗嘉兴网站建设方案优化
  • B2B第三方网站建设的流程优化关键词哪家好
  • 百度推广开户费用标准百度seo快速排名优化软件
  • 建筑网站推荐知乎app怎么推广运营
  • 自建博客网站阿里云免费建站
  • 台州网站建设公司.广州网站设计专注乐云seo
  • 怎样做集装箱网站四川省人民政府官网
  • 推荐几个好看的网站域名注册查询官网
  • 网站建设视频教程百度荤seo公司
  • 做移动端网站乐山网站seo
  • 开发公司安全生产管理制度免费seo教程分享
  • 浙江省建设信息港网站个人模板建站
  • 继续加强网站建设大侠seo外链自动群发工具
  • 建设网络强国征文seo手机排名软件
  • 做网站数据库要哪一种好线上营销方式
  • 搭建平台网站seo专业术语
  • 网站推广连接怎么做的大数据营销是什么
  • 手机版网站开发的功能点农村电商平台
  • 如何优化wordpress网站百度网址提交入口平台
  • 创业做网站还是软件好营销网站建设哪家好
  • dedecms新网站 上传到万网的空间泰安网站推广优化
  • 阿里备案成功后怎么做网站武汉今日头条最新消息
  • wordpress 知识 管理梅花seo 快速排名软件
  • 有没有可以做翻译的网站企业网站设计方案
  • 网站做推广企业游戏推广员判几年
  • 我市强化属地网站建设建设网站制作
  • onethink做的企业网站长沙百度提升排名
  • 邹城有做网站的吗开发一个app需要多少钱?