Skip to content

Commit f0c9a46

Browse files
author
illarionov-company
committed
change resize logic
1 parent b3b85ec commit f0c9a46

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

src-lib/engine/TheSuperSonicPluginForScrollBasedAnimation.ts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import { Observer } from "../engine/Observer"
1010
export class TheSuperSonicPluginForScrollBasedAnimation {
1111
/** IntersectionObserver instance */
1212
observer: Observer | null = null
13-
/** Debounced window.resize listener */
14-
resizeWrapper: Function | null = null
13+
14+
/** Debounced resize listener */
15+
onResize: EventListener | null = null
1516

1617
constructor(config: MainConfiguration) {
1718
Globals.initConfig(config)
@@ -95,42 +96,26 @@ export class TheSuperSonicPluginForScrollBasedAnimation {
9596
/** Updates global scroll */
9697
updateScroll() {
9798
Globals.scroll =
98-
window.pageYOffset || window.scrollY || document.documentElement.scrollTop || document.body.scrollTop
99+
window.scrollY || window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
99100
}
100101

101102
/** Add event listeners */
102103
addEventListeners() {
103-
this.resizeWrapper = debounce(() => {
104+
this.onResize = () => {
104105
this.updateLimits()
105106
this.render({ useActiveDrivers: false })
106-
})
107+
}
107108

108-
window.addEventListener("resize", this.onResize.bind(this))
109+
window.addEventListener("resize", this.onResize)
109110
}
110111

111112
/** Removes event listeners */
112113
removeEventListeners() {
113-
window.removeEventListener("resize", this.onResize)
114-
}
115-
116-
/** Debounced window.resize listener */
117-
onResize() {
118-
this.resizeWrapper!()
114+
window.removeEventListener("resize", this.onResize!)
119115
}
120116

121117
static Driver = Driver
122118
static Property = Property
123119
static Element = Element
124120
static Globals = Globals
125121
}
126-
127-
function debounce(func: Function) {
128-
let timer: any
129-
return () => {
130-
clearTimeout(timer)
131-
timer = setTimeout(() => {
132-
// @ts-ignore
133-
func.apply(this)
134-
}, 500)
135-
}
136-
}

0 commit comments

Comments
 (0)