刚接触react,边看文档边动手,写了个简单的pc端全屏滚动,只支持竖屏滚动,带小圆点(nav)
fullpage.jsx文件
import React from "react";
import "./fullpage.less";
import {
throttle } from "utils/loadash";
class Fullpage extends React.Component {
constructor(props) {
super(props);
this.state = {
currentPage: 1,
pageList: this.props.children,
};
this.initPageListFromPropsChildren(); // 类似于vue的插槽,props带过来的children(FullpageItem)
this.handleScroll = throttle(this.handleScroll, 600, true); //屏幕滚动时的节流函数
}
debounceHandleScroll = (e) => {
e.persist();
this.handleScroll(e);
};
changeCurrentPage(index) {
this.setState({
currentPage: index });
}
handleScroll(e) {
if (e.deltaY > 0) {
if (this.state.currentPage === this.state.pageList.length) return;
this.changeCurrentPage(