Created
October 23, 2023 06:04
-
-
Save jimjam-slam/aff6f166ec81c086f054d19dc881420b to your computer and use it in GitHub Desktop.
Quick observer for reacting to screen orientation in Observable and Quarto notebooks. Assumes portrait on desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isLandscape = Generators.observe(next => { | |
// yield initial value | |
next(screen.orientation?.angle == 90 || screen.orientation?.angle == 180); | |
// define event listener | |
const listener = () => next(screen.orientation?.angle == 90 || screen.orientation?.angle == 180); | |
// attach event listener | |
screen.orientation.addEventListener("change", listener); | |
// return func to cleanup event listener on destruction | |
return () => screen.orientation.removeEventListener("change", listener); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment