Commit 2ba897f0 authored by 陈帅's avatar 陈帅

fix #1989 Fix problem with scroll not working

parent ec93edcc
......@@ -16,11 +16,11 @@ class HeaderView extends PureComponent {
};
componentDidMount() {
document.getElementById('root').addEventListener('scroll', this.handScroll);
document.addEventListener('scroll', this.handScroll, { passive: true });
}
componentWillUnmount() {
document.getElementById('root').removeEventListener('scroll', this.handScroll);
document.removeEventListener('scroll', this.handScroll);
}
getHeadWidth = () => {
......@@ -71,16 +71,22 @@ class HeaderView extends PureComponent {
}
};
handScroll = () => {
handScroll = e => {
const { autoHideHeader } = this.props;
const { visible } = this.state;
if (!autoHideHeader) {
return;
}
const { scrollTop } = document.getElementById('root');
const scrollTop = document.body.scrollTop + document.documentElement.scrollTop;
if (!this.ticking) {
this.ticking = false;
requestAnimationFrame(() => {
if (this.oldScrollTop > scrollTop) {
this.setState({
visible: true,
});
this.scrollTop = scrollTop;
return;
}
if (scrollTop > 400 && visible) {
this.setState({
visible: false,
......@@ -91,9 +97,12 @@ class HeaderView extends PureComponent {
visible: true,
});
}
this.oldScrollTop = scrollTop;
this.ticking = false;
return;
});
}
this.ticking = false;
};
render() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment