Skip to content

Commit

Permalink
improve(editor): make fixed scroll when zoom in block
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 authored and tiensonqin committed Feb 4, 2021
1 parent 1b13896 commit f0b5bcd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/frontend/components/page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
(for [[original-name name] pages]
[:li {:key (str "tagged-page-" name)}
[:a {:href (rfe/href :page {:name name})}
original-name]])])]])))
original-name]])] false)]])))

(defonce last-route (atom :home))
;; A page is just a logical block
Expand Down
19 changes: 10 additions & 9 deletions src/main/frontend/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
(-write writer (str "\"" (.toString sym) "\"")))))

;; doms
#?(:cljs (defn html-node [] js/document.documentElement))
#?(:cljs (defn app-scroll-container-node [] js/document.documentElement))

#?(:cljs
(defn ios?
Expand Down Expand Up @@ -392,26 +392,27 @@
(when-not (re-find #"^/\d+$" elem-id)
(when elem-id
(when-let [elem (gdom/getElement elem-id)]
(.scroll (html-node)
(.scroll (app-scroll-container-node)
#js {:top (let [top (element-top elem 0)]
(if (> top 68)
(- top 68)
top))
(if (< top 256)
0 top))
:behavior "smooth"}))))))

#?(:cljs
(defn scroll-to
([pos]
(scroll-to (html-node) pos))
([node pos]
(scroll-to pos true))
([pos animate?]
(scroll-to (app-scroll-container-node) pos animate?))
([node pos animate?]
(.scroll node
#js {:top pos
:behavior "smooth"}))))
:behavior (if animate? "smooth" "auto")}))))

#?(:cljs
(defn scroll-to-top
[]
(scroll-to 0)))
(scroll-to 0 false)))

(defn url-encode
[string]
Expand Down

0 comments on commit f0b5bcd

Please sign in to comment.