fix: scroll to top when switch to a new page

Resolved #632
pull/719/head^2
Tienson Qin 2020-11-24 21:50:39 +08:00
parent 0d6856d234
commit 89c807c2a7
3 changed files with 11 additions and 6 deletions

View File

@ -327,7 +327,10 @@
[:p
[:code.mr-2 "Embed page:"]
(page-cp config {:page/name page-name})]
(when (not= (string/lower-case current-page) page-name)
(when (or
(not current-page)
(and current-page
(not= (string/lower-case current-page) page-name)))
(blocks-container blocks (assoc config
:embed? true
:ref? false)))]))

View File

@ -81,8 +81,9 @@
(defn scroll-and-highlight!
[state]
(when-let [fragment (util/get-fragment)]
(highlight-element! fragment))
(if-let [fragment (util/get-fragment)]
(highlight-element! fragment)
(util/scroll-to-top))
state)
(defn add-style-if-exists!

View File

@ -322,9 +322,10 @@
(defn scroll-to
[pos]
(.scroll (gdom/getElement "main-content")
#js {:top pos
:behavior "smooth"}))
(when-let [main-content (gdom/getElement "main-content")]
(.scroll main-content
#js {:top pos
:behavior "smooth"})))
(defn scroll-to-top
[]