Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export default class Headroom extends Component {
// Class variables.
this.currentScrollY = 0
this.lastKnownScrollY = 0
this.scrollTicking = false
this.resizeTicking = false
this.scrollHandler = undefined
this.resizeHandler = undefined
this.eventListenerOptions = false
this.state = {
state: 'unfixed',
Expand Down Expand Up @@ -179,6 +179,12 @@ export default class Headroom extends Component {
this.handleScroll,
this.eventListenerOptions
)
if (this.scrollHandler) {
raf.cancel(this.scrollHandler)
}
if (this.resizeHandler) {
raf.cancel(this.resizeHandler)
}
}

setRef = ref => (this.inner = ref)
Expand All @@ -187,7 +193,7 @@ export default class Headroom extends Component {
this.setState({
height: this.inner ? this.inner.offsetHeight : '',
})
this.resizeTicking = false
this.resizeHandler = undefined
}

getScrollY = () => {
Expand Down Expand Up @@ -256,16 +262,14 @@ export default class Headroom extends Component {
}

handleScroll = () => {
if (!this.scrollTicking) {
this.scrollTicking = true
raf(this.update)
if (!this.scrollHandler) {
this.scrollHandler = raf(this.update)
}
}

handleResize = () => {
if (!this.resizeTicking) {
this.resizeTicking = true
raf(this.setHeightOffset)
if (!this.resizeHandler) {
this.resizeHandler = raf(this.setHeightOffset)
}
}

Expand Down Expand Up @@ -339,7 +343,7 @@ export default class Headroom extends Component {
}

this.lastKnownScrollY = this.currentScrollY
this.scrollTicking = false
this.scrollHandler = undefined
}

render() {
Expand Down