Commit 2ba897f0 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

fix #1989 Fix problem with scroll not working

parent ec93edcc
...@@ -16,11 +16,11 @@ class HeaderView extends PureComponent { ...@@ -16,11 +16,11 @@ class HeaderView extends PureComponent {
}; };
componentDidMount() { componentDidMount() {
document.getElementById('root').addEventListener('scroll', this.handScroll); document.addEventListener('scroll', this.handScroll, { passive: true });
} }
componentWillUnmount() { componentWillUnmount() {
document.getElementById('root').removeEventListener('scroll', this.handScroll); document.removeEventListener('scroll', this.handScroll);
} }
getHeadWidth = () => { getHeadWidth = () => {
...@@ -71,16 +71,22 @@ class HeaderView extends PureComponent { ...@@ -71,16 +71,22 @@ class HeaderView extends PureComponent {
} }
}; };
handScroll = () => { handScroll = e => {
const { autoHideHeader } = this.props; const { autoHideHeader } = this.props;
const { visible } = this.state; const { visible } = this.state;
if (!autoHideHeader) { if (!autoHideHeader) {
return; return;
} }
const { scrollTop } = document.getElementById('root'); const scrollTop = document.body.scrollTop + document.documentElement.scrollTop;
if (!this.ticking) { if (!this.ticking) {
this.ticking = false;
requestAnimationFrame(() => { requestAnimationFrame(() => {
if (this.oldScrollTop > scrollTop) {
this.setState({
visible: true,
});
this.scrollTop = scrollTop;
return;
}
if (scrollTop > 400 && visible) { if (scrollTop > 400 && visible) {
this.setState({ this.setState({
visible: false, visible: false,
...@@ -91,9 +97,12 @@ class HeaderView extends PureComponent { ...@@ -91,9 +97,12 @@ class HeaderView extends PureComponent {
visible: true, visible: true,
}); });
} }
this.oldScrollTop = scrollTop;
this.ticking = false; this.ticking = false;
return;
}); });
} }
this.ticking = false;
}; };
render() { 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