javascript – js_of_ocaml和event_listener
作者:互联网
我在js_of_ocaml中有一个div,我想分配一个onmouseover事件,比如
deck_div ## onm ouseover< - (fun() - >(* do stuff *))
但是,期望的函数类型是
(Dom_html.divElement Js.t,Dom_html.mouseEvent Js.t)Dom_html.event_listener
如何构造这个事件监听器? deck_div没有方法addEventListener.
解决方法:
几个月前我正在思考同样的问题而AFAIR我已经成功使用了Html.handler.也许这个例子会对你有帮助
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
....
标签:javascript,events,ocaml,js-of-ocaml 来源: https://codeday.me/bug/20190831/1777214.html