jjb-lc-designable
Version:
基于alibaba-designable源码二次封装的表单设计器。
35 lines (30 loc) • 1.03 kB
text/typescript
import { EventDriver, globalThisPolyfill } from 'jjb-lc-designable/shared'
import { Engine } from '../models/Engine'
import { ViewportScrollEvent } from '../events'
export class ViewportScrollDriver extends EventDriver<Engine> {
request = null
onScroll = (e: UIEvent) => {
e.preventDefault()
this.request = globalThisPolyfill.requestAnimationFrame(() => {
this.dispatch(
new ViewportScrollEvent({
scrollX: this.contentWindow.scrollX,
scrollY: this.contentWindow.scrollY,
width: this.contentWindow.document.body.clientWidth,
height: this.contentWindow.document.body.clientHeight,
innerHeight: this.contentWindow.innerHeight,
innerWidth: this.contentWindow.innerWidth,
view: this.contentWindow,
target: e.target,
})
)
cancelAnimationFrame(this.request)
})
}
attach() {
this.addEventListener('scroll', this.onScroll)
}
detach() {
this.removeEventListener('scroll', this.onScroll)
}
}