-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
27 lines (23 loc) · 854 Bytes
/
index.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
import './gen/tailwind-gen.css';
import './style.css';
const { Elm } = require("./src/Main.elm");
const pagesInit = require("elm-pages");
const smoothScrollToPercentage = ({ domId, left, top }) => {
const elem = document.getElementById(domId);
if (elem != null) {
elem.scrollTo({
left: left != null ? left * elem.scrollWidth : undefined,
top: top != null ? top * elem.scrollHeight : undefined,
behavior: 'smooth'
});
}
}
pagesInit({ mainElmModule: Elm.Main }).then(app => {
app.ports.smoothScrollToPercentagePort.subscribe(smoothScrollToPercentage);
app.ports.scrollToBottom.subscribe(() => {
// Wait one frame for Elm to render additional elements (that push the page down)
window.requestAnimationFrame(() =>
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' })
);
});
});