Created
June 5, 2015 16:25
-
-
Save TheSeamau5/a7e5863c1946727d0c52 to your computer and use it in GitHub Desktop.
Div follows mouse example
This file contains hidden or 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
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