Advertisement
monstasat

resizeObserver

Mar 14th, 2019
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.96 KB | None | 0 0
  1. open Js_of_ocaml
  2.  
  3. class type resizeEntry =
  4.   object
  5.     method target : Dom.node Js.t Js.readonly_prop
  6.     method contentRect : Dom_html.clientRect Js.t Js.readonly_prop
  7.   end
  8.  
  9. class type resizeObserver =
  10.   object
  11.     method observe : 'a. (#Dom.node as 'a) Js.t -> unit Js.meth
  12.     method unobserve : 'a. (#Dom.node as 'a) Js.t -> unit Js.meth
  13.     method disconnect : unit Js.meth
  14.   end
  15.  
  16. let resizeObserver = Js.Unsafe.global##._ResizeObserver
  17.  
  18. let is_supported () = Js.Optdef.test resizeObserver
  19.  
  20. let resizeObserver :
  21.       ((resizeEntry Js.t Js.js_array Js.t -> unit)
  22.          Js.callback -> resizeObserver Js.t) Js.constr =
  23.   resizeObserver
  24.  
  25. let observe ~(node : #Dom.node Js.t)
  26.       ~(f : resizeEntry Js.t Js.js_array Js.t -> unit)
  27.       () : resizeObserver Js.t =
  28.   let (obs : resizeObserver Js.t) = new%js resizeObserver (Js.wrap_callback f) in
  29.   obs##observe node;
  30.   obs
  31.  
  32. let disconnect (obs : resizeObserver Js.t) : unit =
  33.   obs##disconnect
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement