最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

react實現(xiàn)導(dǎo)航欄二級聯(lián)動

 更新時間:2022年03月08日 09:54:12   作者:至_臻  
這篇文章主要為大家詳細介紹了react實現(xiàn)導(dǎo)航欄二級聯(lián)動,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了react實現(xiàn)導(dǎo)航欄二級聯(lián)動的具體代碼,供大家參考,具體內(nèi)容如下

效果圖

js代碼

import { Component } from "react";
import './scroll.less'
?
class Scroll extends Component {
? ? constructor(...args) {
? ? ? ? super(...args)
? ? ? ? this.state = {
? ? ? ? ? ? list: [
? ? ? ? ? ? ? ? { id: 1, title: '列表1' },
? ? ? ? ? ? ? ? { id: 2, title: '列表2' },
? ? ? ? ? ? ? ? { id: 3, title: '列表3' },
? ? ? ? ? ? ? ? { id: 4, title: '列表4' },
? ? ? ? ? ? ? ? { id: 5, title: '列表5' },
? ? ? ? ? ? ? ? { id: 6, title: '列表6' },
? ? ? ? ? ? ? ? { id: 7, title: '列表7' },
? ? ? ? ? ? ? ? { id: 8, title: '列表8' },
? ? ? ? ? ? ? ? { id: 9, title: '列表9' },
? ? ? ? ? ? ? ? { id: 10, title: '列表10' },
? ? ? ? ? ? ? ? { id: 11, title: '列表11' },
? ? ? ? ? ? ? ? { id: 12, title: '列表12' },
? ? ? ? ? ? ? ? { id: 13, title: '列表13' },
? ? ? ? ? ? ? ? { id: 14, title: '列表14' },
? ? ? ? ? ? ? ? { id: 15, title: '列表15' },
? ? ? ? ? ? ? ? { id: 16, title: '列表16' },
? ? ? ? ? ? ? ? { id: 17, title: '列表17' },
? ? ? ? ? ? ],
? ? ? ? ? ? LeftList: [
? ? ? ? ? ? ? ? { id: 1, title: '列表1', height: 800 },
? ? ? ? ? ? ? ? { id: 2, title: '列表2', height: 600 },
? ? ? ? ? ? ? ? { id: 3, title: '列表3', height: 500 },
? ? ? ? ? ? ? ? { id: 4, title: '列表4', height: 900 },
? ? ? ? ? ? ? ? { id: 5, title: '列表5', height: 450 },
? ? ? ? ? ? ? ? { id: 6, title: '列表6', height: 300 },
? ? ? ? ? ? ? ? { id: 7, title: '列表7', height: 900 },
? ? ? ? ? ? ? ? { id: 8, title: '列表8', height: 1010 },
? ? ? ? ? ? ? ? { id: 9, title: '列表9', height: 300 },
? ? ? ? ? ? ? ? { id: 10, title: '列表10', height: 600 },
? ? ? ? ? ? ? ? { id: 11, title: '列表11', height: 400 },
? ? ? ? ? ? ? ? { id: 12, title: '列表12', height: 760 },
? ? ? ? ? ? ? ? { id: 13, title: '列表13', height: 580 },
? ? ? ? ? ? ? ? { id: 14, title: '列表14', height: 630 },
? ? ? ? ? ? ? ? { id: 15, title: '列表15', height: 540 },
? ? ? ? ? ? ? ? { id: 16, title: '列表16', height: 983 },
? ? ? ? ? ? ? ? { id: 17, title: '列表17', height: 610 },
? ? ? ? ? ? ],
? ? ? ? ? ? curr: 0,//存儲下標
? ? ? ? }
? ? ? ? // 默認添加一個 因為第一個的scrollTop值是0
? ? ? ? this.LeftHeight = [0]
? ? ? ? // 滾動的開關(guān)
? ? ? ? this.Swich = true
? ? }
? ? // 渲染完成獲取每一個列表距離頂部的距離
? ? componentDidMount() {
? ? ? ? // 定義為0 每次就可以循環(huán)加起來就是盒子距離頂部的距離
? ? ? ? this.Height = 0
? ? ? ? // 循環(huán)獲取每一個的高
? ? ? ? for (var i = 0; i < this.state.LeftList.length - 1; i++) {
? ? ? ? ? ? this.Height += this.state.LeftList[i].height
? ? ? ? ? ? // 將它添加到數(shù)組中
? ? ? ? ? ? this.LeftHeight.push(this.Height)
? ? ? ? }
? ? }
? ? // ? 點擊左側(cè)列表 點擊獲取下標
? ? fnTab(Ind) {
? ? ? ? // 點擊的時候讓右邊的滾動事件為false
? ? ? ? this.Swich = false
? ? ? ? // 存儲下標
? ? ? ? this.setState({
? ? ? ? ? ? curr: Ind
? ? ? ? })
? ? ? ? // 根據(jù)下標取出數(shù)組中對應(yīng)下標的scrollTop值 ?就讓右邊的scrollTop為數(shù)組中取出的值
? ? ? ? this.refs['rightItem'].scrollTop = this.LeftHeight[Ind];
?
? ? ? ? // this.refs.scrollLeft.scrollTop = this.state.curr - 4 * 58.89
? ? }
? ? FnScroll() {
? ? ? ? // 監(jiān)聽滾動
? ? ? ? this.scrollTop = this.refs['rightItem'].scrollTop
? ? ? ? // 這邊用開關(guān)判斷是否執(zhí)行
? ? ? ? if (this.Swich) {
? ? ? ? ? ? // 存放下標
? ? ? ? ? ? let num = 0
? ? ? ? ? ? // 循環(huán)取出數(shù)組中的數(shù)值
? ? ? ? ? ? for (var i = 0; i < this.LeftHeight.length - 1; i++) {
? ? ? ? ? ? ? ? if (this.scrollTop >= this.LeftHeight[i]) {
? ? ? ? ? ? ? ? ? ? num = i
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? // 存儲下標
? ? ? ? ? ? this.setState({
? ? ? ? ? ? ? ? curr: num
? ? ? ? ? ? })
? ? ? ? }
? ? ? ? // 判斷滾動的值和數(shù)組中的值相等 開關(guān)為true
? ? ? ? if (this.scrollTop == this.LeftHeight[this.state.curr]) {
? ? ? ? ? ? setTimeout(() => {
? ? ? ? ? ? ? ? this.Swich = true;
? ? ? ? ? ? });
? ? ? ? }
? ? }
? ? render() {
? ? ? ? return (
? ? ? ? ? ? <div className='box'>
? ? ? ? ? ? ? ? <div className='scroll'>
? ? ? ? ? ? ? ? ? ? <div className='scroll-right' ref='scrollLeft'>
? ? ? ? ? ? ? ? ? ? ? ? {this.state.list.map((item, index) => <div className='right-item' className={this.state.curr === index ? "active" : "right-item"} key={item.id} onClick={this.fnTab.bind(this, index)} >{item.title}</div>)}
? ? ? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? ? ? ? ? <div className='scroll-left' ref='rightItem' onScroll={this.FnScroll.bind(this)}>
? ? ? ? ? ? ? ? ? ? ? ? {this.state.LeftList.map((item) => <div className='left-item' key={item.id} style={{ height: item.height }}><div className='item-title'>{item.title}</div></div>)}
? ? ? ? ? ? ? ? ? ? </div>
?
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? )
? ? }
}
export default Scroll

less代碼

* {
? ? margin: 0;
? ? padding: 0;
}
?
.box {
? ? width: 100vw;
? ? height: 100vh;
? ? background: red;
?
? ? .scroll {
? ? ? ? width: 100vw;
? ? ? ? height: 100vh;
? ? ? ? display: flex;
?
? ? ? ? // 右邊列表
? ? ? ? .scroll-right {
? ? ? ? ? ? width: 25vw;
? ? ? ? ? ? background: aqua;
? ? ? ? ? ? font-size: 28px;
? ? ? ? ? ? height: 100vh;
? ? ? ? ? ? overflow-y: auto;
?
? ? ? ? ? ? .right-item {
? ? ? ? ? ? ? ? width: 25vw;
? ? ? ? ? ? ? ? height: 80px;
? ? ? ? ? ? ? ? text-align: center;
? ? ? ? ? ? ? ? line-height: 80px;
? ? ? ? ? ? ? ? border-bottom: 1px solid #ccc;
? ? ? ? ? ? }
?
? ? ? ? ? ? .active {
? ? ? ? ? ? ? ? height: 80px;
? ? ? ? ? ? ? ? text-align: center;
? ? ? ? ? ? ? ? line-height: 80px;
? ? ? ? ? ? ? ? background: #0f0;
? ? ? ? ? ? }
? ? ? ? }
?
? ? ? ? // 左邊內(nèi)容
? ? ? ? .scroll-left {
? ? ? ? ? ? width: 75vw;
? ? ? ? ? ? height: 100vh;
? ? ? ? ? ? overflow-y: auto;
? ? ? ? ? ? //滾動的更加絲滑
? ? ? ? ? ? scroll-behavior: smooth;
?
? ? ? ? ? ? .left-item {
? ? ? ? ? ? ? ? width: 75vw;
? ? ? ? ? ? ? ? font-size: 30px;
? ? ? ? ? ? ? ? text-align: center;
?
?
? ? ? ? ? ? ? ? .item-title {
? ? ? ? ? ? ? ? ? ? height: 30px;
? ? ? ? ? ? ? ? ? ? background: #ccc;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解React的回調(diào)渲染模式

    詳解React的回調(diào)渲染模式

    這篇文章主要介紹了詳解React的回調(diào)渲染模式,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • React Native 通告消息豎向輪播組件的封裝

    React Native 通告消息豎向輪播組件的封裝

    這篇文章主要介紹了React Native 通告消息豎向輪播組件的封裝,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • react表單受控的實現(xiàn)方案

    react表單受控的實現(xiàn)方案

    數(shù)據(jù)的受控控制一直是react里的一個痛點,當(dāng)我想要實現(xiàn)一個輸入框的受控控制時,我需要定義一個onChange和value,手動去實現(xiàn)數(shù)據(jù)的綁定,本文小編給大家介紹了react表單受控的實現(xiàn)方案,需要的朋友可以參考下
    2023-12-12
  • React快速入門教程

    React快速入門教程

    本文主要介紹了React的相關(guān)知識,具有一定的參考價值,下面跟著小編一起來看下吧
    2017-01-01
  • 詳解在React.js中使用PureComponent的重要性和使用方式

    詳解在React.js中使用PureComponent的重要性和使用方式

    這篇文章主要介紹了詳解在React.js中使用PureComponent的重要性和使用方式,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • React中setState/useState的使用方法詳細介紹

    React中setState/useState的使用方法詳細介紹

    這篇文章主要介紹了React中setState/useState的使用方法,useState 和 setState 在React開發(fā)過程中 使用很頻繁,但很多人都停留在簡單的使用階段,并沒有正在了解它們的執(zhí)行機制
    2023-04-04
  • react使用antd表單賦值,用于修改彈框的操作

    react使用antd表單賦值,用于修改彈框的操作

    這篇文章主要介紹了react使用antd表單賦值,用于修改彈框的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-10-10
  • react中關(guān)于Context/Provider/Consumer傳參的使用

    react中關(guān)于Context/Provider/Consumer傳參的使用

    這篇文章主要介紹了react中關(guān)于Context/Provider/Consumer傳參的使用,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 在React中編寫樣式的六種方式

    在React中編寫樣式的六種方式

    在React中,編寫樣式主要有以下幾種方式,內(nèi)聯(lián)樣式,外部樣式表,CSS Modules,Styled Components,Emotion和Radium這六種樣式,下面我將針對上面提到的6種方式給出詳細的代碼示例,需要的朋友可以參考下
    2024-01-01
  • React Native 中添加自定義字體的方法

    React Native 中添加自定義字體的方法

    這篇文章主要介紹了如何在 React Native 中添加自定義字體,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-08-08

最新評論

铁岭县| 舞阳县| 吐鲁番市| 宁城县| 封开县| 吉木乃县| 章丘市| 平果县| 滦南县| 诸城市| 桐柏县| 汾阳市| 芜湖市| 阜城县| 平昌县| 太湖县| 博乐市| 陆川县| 龙江县| 雷山县| 于田县| 宾阳县| 山西省| 商水县| 黄浦区| 郁南县| 镶黄旗| 海晏县| 东乌珠穆沁旗| 屯留县| 蓬安县| 历史| 大田县| 夏河县| 莱芜市| 宕昌县| 建阳市| 万源市| 易门县| 突泉县| 东山县|