Мне бы хотелось узнать атрибут html элемента в Elm, например, ее координаты. Я пытался с Json.Decode.Я хотел бы узнать атрибут html элемента в Elm
Я новичок в Elm, и это предназначено для обучения.
Это простой код, я использую Elm 0.18:
module Stamps exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
type alias Model =
{}
type Msg
= NoOp
| Clicking
model : Model
model =
{}
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
NoOp ->
(model, Cmd.none)
Clicking ->
let
_ =
Debug.log "msg1" model
in
(model, Cmd.none)
view : Model -> Html Msg
view model =
div
[ Html.Attributes.style
[ ("backgroundColor", "blue")
, ("height", "300px")
, ("width", "300px")
, ("position", "relative")
, ("left", "100px")
, ("top", "50px")
]
, Html.Attributes.class
"parent"
]
[ div
[ Html.Attributes.style
[ ("background-color", "#3C8D2F")
, ("cursor", "move")
, ("width", "100px")
, ("height", "100px")
, ("border-radius", "4px")
, ("position", "absolute")
, ("color", "white")
, ("display", "flex")
, ("align-items", "center")
, ("justify-content", "center")
]
, Html.Attributes.class
"children"
, Html.Events.onClick Clicking
]
[]
]
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
main : Program Never Model Msg
main =
Html.program
{ init = (model, Cmd.none)
, update = update
, view = view
, subscriptions = subscriptions
}