单击Elm时使图像移动位置

时间:2018-03-16 16:40:40

标签: functional-programming elm

当我点击某个位置时,我应该如何编辑视图以使图像保持在固定位置。目前,它遵循鼠标。

update : Msg -> Model -> (Model,Cmd.Cmd Msg)
update (MouseMsg pos) model = ({ model | position = {x = pos.x, y = pos.y} },Cmd.none)


view : Model -> Html.Html Msg
view model = let
posX = toString model.position.x
posY = toString model.position.y
in
svg [ onClick model ][width "10000",height "10000"] [circle [cx posX, cy posY, r "50", fill "blue" ] []]

1 个答案:

答案 0 :(得分:0)

当然,够容易! :)

将此添加到您的模型中

dragging : Bool 

将此添加到您的更新

({ model | dragging = False}, Cmd.none)

并将其添加到您的init

dragging = True