Commit ef9571c2 by FE

scroll in search result

parent 2be2ca3f
...@@ -32,7 +32,9 @@ class SearchResult extends PureComponent { ...@@ -32,7 +32,9 @@ class SearchResult extends PureComponent {
searchHistory: JSON.parse(localStorage.getItem('searchHistory')) || [], searchHistory: JSON.parse(localStorage.getItem('searchHistory')) || [],
fixedHeader: false, fixedHeader: false,
searchHeadStyle: {top: 0}, searchHeadStyle: {top: 0},
swipeDirection: this.swipeUp swipeDirection: this.swipeUp,
isHide: false,
basicTop: 0
} }
componentDidMount() { componentDidMount() {
...@@ -76,61 +78,65 @@ class SearchResult extends PureComponent { ...@@ -76,61 +78,65 @@ class SearchResult extends PureComponent {
} }
handleScroll = throttle(() => { handleScroll = throttle(() => {
let y = window.scrollY, let y = window.scrollY < 0? 0 : window.scrollY,
headY = this.searchHead.current.offsetTop; headY = this.searchHead.current.offsetTop,
console.log(headY,'headY'); h = this.searchHead.current.offsetHeight;
console.log(document.querySelector('body').offsetHeight); if(y > this.prevScrollY) {
// 向上滑动
if (y < this.prevScrollY && y > 0) {
console.log(0);
console.log(this.state.swipeDirection);
if (this.state.swipeDirection === this.swipeDown) {
console.log(1);
y <= headY && this.state.searchHeadStyle.position !== 'fixed' &&
this.setState({
searchHeadStyle: {
top: `0`,
position: 'fixed'
}
})
} else {
console.log(2);
this.setState({
swipeDirection: this.swipeDown
}, () => {
if (this.state.swipeDirection === this.swipeDown) {
let h = y > document.querySelector('body').offsetHeight? document.querySelector('body').offsetHeight: y;
let h1 = this.searchHead.current.offsetHeight
this.setState({
searchHeadStyle: {
// top: `${h > headY ? h - h1 : h}px`
top: `${y}px`
}
})
}
})
}
} else {
console.log(3);
this.state.swipeDirection !== this.swipeUp &&
this.setState({ this.setState({
swipeDirection: this.swipeUp,
searchHeadStyle: { searchHeadStyle: {
position: 'absolute', top : `${-h}px`
top: `${y}px`
} }
}) });
} }
if(y < this.prevScrollY) {
this.setState({
searchHeadStyle: {
top: 0
}
});
}
// if (y < this.prevScrollY) {
// if (this.state.swipeDirection === this.swipeDown) {
// y <= headY && this.state.searchHeadStyle.position !== 'fixed' &&
// this.setState({
// searchHeadStyle: {
// top: `0`,
// position: 'fixed'
// }
// })
// } else {
// this.setState({
// swipeDirection: this.swipeDown
// }, () => {
// if (this.state.swipeDirection === this.swipeDown) {
// let h = y > document.querySelector('body').offsetHeight? document.querySelector('body').offsetHeight: y;
// let h1 = this.searchHead.current.offsetHeight
// this.setState({
// searchHeadStyle: {
// // top: `${h > headY ? h - h1 : h}px`
// top: `${y}px`
// }
// })
// }
// })
// }
// } else {
// this.state.swipeDirection !== this.swipeUp &&
// this.setState({
// swipeDirection: this.swipeUp,
// searchHeadStyle: {
// position: 'absolute',
// top: `${y}px`
// }
// })
// }
this.prevScrollY = y; this.prevScrollY = y;
}, 0) }, 0)
render() { render() {
const {courseList} = this.state const { courseList, isHide } = this.state;
return ( return (
<div <div
...@@ -142,6 +148,7 @@ class SearchResult extends PureComponent { ...@@ -142,6 +148,7 @@ class SearchResult extends PureComponent {
searchHistory={this.state.searchHistory} searchHistory={this.state.searchHistory}
style={this.state.searchHeadStyle} style={this.state.searchHeadStyle}
ref={this.searchHead} ref={this.searchHead}
isHide={isHide}
/> />
{ {
......
.search-result { .search-result {
padding-top: 44px; padding-top: 44px;
.search-head{ .search-head {
position: absolute; // position: absolute;
position: fixed;
top: 0; top: 0;
left: 0; left: 0;
width: 100%; width: 100%;
z-index: 10; z-index: 10;
transition: top 0.5 ease;
&.hide {
top: -44px;
}
} }
ul { ul {
......
...@@ -41,6 +41,7 @@ class SearchHead extends PureComponent { ...@@ -41,6 +41,7 @@ class SearchHead extends PureComponent {
const { isFocus } = this.state; const { isFocus } = this.state;
const cls = classnames('submit-btn', {'submit-btn--active': isFocus}) const cls = classnames('submit-btn', {'submit-btn--active': isFocus})
return ( return (
<div className="search-head" style={this.props.style} ref={this.props.forwardedRef}> <div className="search-head" style={this.props.style} ref={this.props.forwardedRef}>
<div className="left" onClick={this.returnPage}> <div className="left" onClick={this.returnPage}>
......
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