$window
The $window element lets you add event listeners or binds to the window.
const online = $store(window.navigator.onLine);
online.subscribe((next) => {
console.log(next ? "Phew! Back online." : "Oh no! Connection lost...");
});
$window({
on: { keydown: ({ key }) => key === "f" && console.log(":(") },
bind: { online }
})
.mount(document.body);The available binds are:
innerWidthinnerHeightscrollXscrollYonlinedevicePixelRatio
All are readonly, except for scrollX and scrollY.