Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Created June 5, 2015 16:25
Show Gist options
  • Select an option

  • Save TheSeamau5/a7e5863c1946727d0c52 to your computer and use it in GitHub Desktop.

Select an option

Save TheSeamau5/a7e5863c1946727d0c52 to your computer and use it in GitHub Desktop.
Div follows mouse example
import Html
import Html.Attributes exposing (style)
import Html.Events exposing (on)
import Signal exposing (mailbox)
import Json.Decode exposing (Decoder, (:=), int)
positionDecoder =
Json.Decode.object2 (,)
("clientX" := int)
("clientY" := int)
{address, signal} = mailbox (0,0)
(=>) = (,)
app (x,y) =
Html.div
[]
[ Html.div
[ style
[ "position" => "absolute"
, "width" => "100vw"
, "height" => "100vh"
]
, on "mousemove" positionDecoder (Signal.message address)
]
[]
, Html.div
[ style
[ "position" => "absolute"
, "background-color" => "red"
, "width" => "50px"
, "height" => "50px"
, "transform" => ("translate(" ++ toString (x - 25) ++ "px" ++ "," ++ toString (y - 25) ++ "px)")
]
]
[]
]
main =
Signal.map app signal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment