~singpolyma/post-part

22d2ed1b40003338aa40b2f3c9e6e3a04e8be737 — Stephen Paul Weber 2 years ago 3b18197
Hide on page load
1 files changed, 7 insertions(+), 2 deletions(-)

M Main.purs
M Main.purs => Main.purs +7 -2
@@ 37,13 37,18 @@ addEventListener' eventType eventTarget cb = do
  listener <- eventListener cb
  addEventListener eventType listener false eventTarget

clipCircle el size x y = do
  style <- Style.style $ Style.fromHTMLElement el
  Style.setProperty style "clip-path" ("circle(" <> size <> " at " <> (show x) <> "px " <> (show y) <> "px)")

main = unsafePartial $ do
  win <- window
  doc <- HTMLDocument.toParentNode <$> Window.document win
  addEventListener' load (Window.toEventTarget win) $ \_ -> do
    Just wallpaper <- querySelector (QuerySelector "#wallpaper") doc
    Just img <- (HTMLElement.fromElement =<< _) <$> querySelector (QuerySelector "#wallpaper > img") doc
    clipCircle img "0" 0 0

    addEventListener' mousemove (Element.toEventTarget wallpaper) $ \e -> do
      let Just mouseEvent = MouseEvent.fromEvent e
      style <- Style.style $ Style.fromHTMLElement img
      Style.setProperty style "clip-path" ("circle(100px at " <> (show $ MouseEvent.offsetX mouseEvent) <> "px " <> (show $ MouseEvent.offsetY mouseEvent) <> "px)")
      clipCircle img "10vw" (MouseEvent.offsetX mouseEvent) (MouseEvent.offsetY mouseEvent)