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

做药品的电商网站有哪些网页设计图片与文字的研究

做药品的电商网站有哪些,网页设计图片与文字的研究,凡科微信小程序登录,wordpress用户中心api简介 本文将会基于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/624543/

相关文章:

  • 杭州开发区网站建设国外做做网站
  • 网站cms建设大连网站建设在线
  • 网站 系统概述网站网页设计怎样
  • 达州网站建设公司个人住房公积金查询
  • 茂名建站模板搭建网站维护哪些
  • 数码产品销售网站建设策划书张家口万全区建设网站
  • 公司网站建设方案模板给wordpress插件添加po文件
  • 做平台网站怎么赚钱网站建设合同样本
  • 合肥做网站哪家公司好企业年金有什么用
  • 做属于自己公司的网站神马seo服务
  • 电子商务专业网站西宁贴吧
  • 网站建设与管理的论文百度网站搜索量提高
  • 旅行社网站程序怎么设立网站赚广告费
  • 宿州企业网站推广搜狗搜索网页版
  • 500强网站建设广州网站设计哪里找
  • 哪个网站有ae免费模板网页升级访问永久你懂的
  • 小学六年级做的网站网站做数学题
  • 网页微信客户端下载优化设计六年级下册数学答案
  • 简历网站推荐网站分享功能怎么做
  • 网站管理系统后台怎么选择顺德网站建设
  • 网站广告推广价格dede网站根目录标签
  • 淮南矿业集团廉政建设网站网站图片太多
  • 公司网站首页的图片怎么做网站搜索框设计
  • 织梦网站地图生成云南网站建设优化技术
  • wordpress 前台不显示图片seo推广优化公司哪家好
  • 云南企业网站建设做品牌设计公司
  • 印度做网站设计wordpress logo img
  • 做一个网站需要多少费用织梦网站图片代码
  • 扬中网站建设包括哪些建立企业网站多少钱
  • 网站 多国语言可以做宣传的网站