Skip to content

Commit

Permalink
fix(Sticky): 延时初始化
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Feb 14, 2019
1 parent ff41f47 commit d5a2ef7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/components/Sticky/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ class MSticky extends component({
disposer = new Disposer()

componentDidMount() {
wx.createSelectorQuery()
.in(this.$scope)
.select(`.${_.sticky}`)
.boundingClientRect(res => {
this.setState({
contentHeight: res.height,
setTimeout(() => {
wx.createSelectorQuery()
.in(this.$scope)
.select(`.${_.sticky}`)
.boundingClientRect(res => {
this.setState({
contentHeight: res.height,
})
})
})
.exec()
const intersectionObserver = wx.createIntersectionObserver(this.$scope)
.exec()
const intersectionObserver = wx.createIntersectionObserver(this.$scope)
;(intersectionObserver.relativeToViewport({ top: 0 }) as any)
.observe(`.${_.sticky}`, (res: wx.ObserveCallbackResult) => {
this.setState({
fixed: res.intersectionRatio <= 0 && res.boundingClientRect.top < 0,
.observe(`.${_.sticky}`, (res: wx.ObserveCallbackResult) => {
this.setState({
fixed: res.intersectionRatio <= 0 && res.boundingClientRect.top < 0,
})
})
})
this.disposer.add(intersectionObserver.disconnect)
this.disposer.add(intersectionObserver.disconnect)
}, 300)
}

componentWillUnmount() {
Expand Down

0 comments on commit d5a2ef7

Please sign in to comment.