2021-08-24 13:36:48 +08:00
|
|
|
import sleep from './sleep'
|
2020-09-02 17:44:14 +08:00
|
|
|
|
2022-03-08 14:03:32 +08:00
|
|
|
const makeScroll = (
|
2021-09-04 19:29:28 +08:00
|
|
|
dom: Element,
|
|
|
|
name: 'scrollTop' | 'scrollLeft',
|
|
|
|
offset: number
|
|
|
|
) => {
|
2020-09-07 16:48:11 +08:00
|
|
|
const eventTarget = dom === document.documentElement ? window : dom
|
2020-09-02 17:44:14 +08:00
|
|
|
dom[name] = offset
|
2020-12-15 11:42:21 +08:00
|
|
|
const evt = new CustomEvent('scroll', {
|
|
|
|
detail: {
|
|
|
|
target: {
|
|
|
|
[name]: offset,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
eventTarget.dispatchEvent(evt)
|
2020-09-02 17:44:14 +08:00
|
|
|
// must use setTimeout instead of nextTick to wait dom change
|
2022-03-08 14:03:32 +08:00
|
|
|
return sleep()
|
2020-09-02 17:44:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default makeScroll
|