From 90aab92a59e07e2c3f09a5dadaa4485248e3a315 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 13 May 2021 08:57:40 +0200 Subject: [PATCH] :sparkles: Add more helpers to util/dom ns. --- frontend/src/app/util/dom.cljs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/frontend/src/app/util/dom.cljs b/frontend/src/app/util/dom.cljs index 95679b7c8..7601435ca 100644 --- a/frontend/src/app/util/dom.cljs +++ b/frontend/src/app/util/dom.cljs @@ -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))))