Skip to content

Instantly share code, notes, and snippets.

@jimjam-slam
Created October 23, 2023 06:04
Show Gist options
  • Save jimjam-slam/aff6f166ec81c086f054d19dc881420b to your computer and use it in GitHub Desktop.
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.
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