Skip to content

Instantly share code, notes, and snippets.

@ethagnawl
Created August 8, 2017 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethagnawl/d1f860a0c5298a2802b21d18e47a02fa to your computer and use it in GitHub Desktop.
Save ethagnawl/d1f860a0c5298a2802b21d18e47a02fa to your computer and use it in GitHub Desktop.
Remove class N seconds after mousemove - subsequent mousemoves pad buffer
-- https://ellie-app.com/3XKKySvspDka1/0
module Main exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html exposing (..)
import Json.Decode as Decode
import Task
import Time
type alias Model =
{ hideAt : Maybe Time.Time
, shown : Bool
}
type Msg
= AttemptToHide Time.Time
| ScheduleHide Time.Time
| Show
show model = ( { model | shown = True } , Task.perform ScheduleHide Time.now)
scheduleHide model time =
let
hideAtTime =
time + (2 * Time.second)
in
( { model
| hideAt = (Just hideAtTime)
}
, Cmd.none
)
attemptToHide model time =
case (model.hideAt) of
Just hideAt ->
case (time > hideAt) of
True ->
( { model
| hideAt = Nothing
, shown = False
}
, Cmd.none
)
False -> model ! []
Nothing -> model ! []
update action model =
case action of
AttemptToHide time -> attemptToHide model time
ScheduleHide time -> scheduleHide model time
Show -> show model
subscriptions model = (Time.every Time.second ChromeAttemptToHide)
view model =
div
[ on "mousemove" (Decode.succeed (ChromeShown))
, classList [ ( "active", model.shown ) ]
]
[
[div [class "default"] text "Default" ]
, [div [class "active"] text "Active" ]
]
init = ({hideAt = Nothing, shown = False}, Cmd.none)
main =
program
{
init = init
, subscriptions = subscriptions
, update = update
, view = view
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment