0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 00:58:26 -05:00

Add more helpers to util/dom ns.

This commit is contained in:
Andrey Antukh 2021-05-13 08:57:40 +02:00 committed by Andrés Moya
parent d613d00bca
commit 90aab92a59

View file

@ -293,3 +293,21 @@
(defn remove-attribute [^js node ^string attr]
(.removeAttribute node attr))
(defn scroll-into-view!
([element]
(.scrollIntoView ^js element false))
([element scroll-top]
(.scrollIntoView ^js element scroll-top)))
(defn is-in-viewport?
[element]
(let [rect (.getBoundingClientRect element)
height (or (.-innerHeight js/window)
(.. js/document -documentElement -clientHeight))
width (or (.-innerWidth js/window)
(.. js/document -documentElement -clientWidth))]
(and (>= (.-top rect) 0)
(>= (.-left rect) 0)
(<= (.-bottom rect) height)
(<= (.-right rect) width))))