-
Notifications
You must be signed in to change notification settings - Fork 3
/
cssvars-js.js
61 lines (51 loc) · 1.56 KB
/
cssvars-js.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var $ = Bliss, $$ = Bliss.$;
// Specific slide demos
document.addEventListener("slidechange", evt => {
var slideId = evt.target.id;
var mousemove = evt => {
document.documentElement.style.setProperty("--mouse-x", evt.clientX / innerWidth);
document.documentElement.style.setProperty("--mouse-y", evt.clientY / innerHeight);
}
if (slideId == "mouse") {
document.addEventListener("mousemove", mousemove);
}
else {
document.removeEventListener("mousemove", mousemove);
}
});
Inspire.hooks.add("slidechange", env => {
if (Inspire.currentSlide.id === "slider") {
setTimeout(() => {
for (input of document.querySelectorAll("input")) {
input.style.setProperty("--value", input.value);
}
document.addEventListener("input", evt => {
if (evt.target.matches(":target input")) {
evt.target.style.setProperty("--value", evt.target.value);
}
});
}, 500);
}
});
var setLength = element => {
element.style.setProperty("--length", element.textContent.length)
};
for (let element of document.querySelectorAll("p.typing")) {
setLength(element);
var observer = new MutationObserver(r => setLength(element));
observer.observe(element, {
characterData: true,
childList: true,
subtree: true
});
}
Inspire.hooks.add("slidechange", env => {
if (Inspire.currentSlide.id === "scrolling" && env.firstTime) {
Inspire.currentSlide.addEventListener("scroll", evt => {
var el = evt.target;
let maxScroll = el.scrollHeight - el.offsetHeight;
let scroll = el.scrollTop / maxScroll;
el.style.setProperty("--scroll", scroll);
}, true);
}
});