Вопрос

I have a div in js_of_ocaml which I want to assign an onmouseover event, like

deck_div##onmouseover <- (fun () -> (* do stuff *) )

However, the function type expected is

(Dom_html.divElement Js.t, Dom_html.mouseEvent Js.t) Dom_html.event_listener

How to construct this event listener? deck_div has no method addEventListener.

Это было полезно?

Решение

I was thinking about same question some months ago and AFAIR I have succeeded with Html.handler. Maybe this example will help you

https://github.com/ocsigen/js_of_ocaml/blob/master/examples/hyperbolic/hypertree.ml#L276

let handle_drag element move stop click =
  let fuzz = 4 in
  element##onmousedown <- Html.handler
    (fun ev ->
       let x0 = ev##clientX and y0 = ev##clientY in
       ....
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top