-
Notifications
You must be signed in to change notification settings - Fork 1
/
scroll.js
45 lines (42 loc) · 1.29 KB
/
scroll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var app = document.querySelector('.botui-app-container')
var con = document.querySelector('.botui-container')
function debounce(func, wait, immediate) {
var timeout;
return function executedFunction() {
var context = this;
var args = arguments;
var later = function () {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
const doTheScroll = (el) => {
el.scrollTop = el.scrollHeight - el.offsetHeight
}
let prev_scroll_top = null
const debounced = debounce(doTheScroll, 100, false)
con.addEventListener('scroll', (e) => {
e.stopPropagation()
const curr_scroll_top = e.target.scrollTop
if (!prev_scroll_top) {
prev_scroll_top = curr_scroll_top
return
}
const diff = curr_scroll_top - prev_scroll_top
if (diff > 0) {
debounced(e.target)
}
prev_scroll_top = curr_scroll_top
console.log('diff', diff)
})
var transport_type = null
var hotel_preference = null
const $container = document.querySelector('.botui-container')
const $optionscontainer = document.querySelector(
'.botui-actions-container',
)