-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
45 lines (41 loc) · 1.14 KB
/
script.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
/**
* Generate animation time
* @param {number} content_width width in px
* @param {number} speed
* @return {number} animation seconds
*/
function generateAnimationSeconds(content_width, speed) {
// Multiply speed by 10
let modifiedSpeed = parseInt(speed * 100);
// Generate seconds
let seconds = Math.round(content_width / modifiedSpeed);
return seconds;
}
/**
* Set property on document
* @param {String} property name
* @param {*} property value
*/
function setPropertyOnDocument(property_name, property_value) {
document.documentElement.style.setProperty(property_name, property_value);
}
// Scrolling speed
const speed = 0.5;
// Get wrapper
const scrollbarWrapper = document.querySelector(".scrollbar-wrapper");
// Generate seconds
const animationSeconds = generateAnimationSeconds(
scrollbarWrapper.scrollWidth,
speed
);
// Set animation time
setPropertyOnDocument("--scrollbar-animation-time", `${animationSeconds}s`);
// Set position
setPropertyOnDocument(
"--scrollbar-move-left-end",
`-${scrollbarWrapper.scrollWidth}px`
);
setPropertyOnDocument(
"--scrollbar-move-right-start",
`-${scrollbarWrapper.scrollWidth}px`
);