Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Implementing js script for scrolling to a target in Clojurescrip - Re-frame

I'm working on a Clojure project, using clojure, clojurescript, re-frame and reagent. There is a button that I want when it is clicked, the user jumps to the related image tag by scrolling. There are lots of buttons that each button should scroll the screen to the target picture.

As I'm new to clojure world, I don't know how to implement the js script into the project. I have created a button on the views.cljs file with dispatch to the events. But where should I implement the js part? As I've found, it must be in the events.cljs file, but if it's correct, I don't know how to implement that.

Please help me with this code. How should the js code looks like when it's going to be implemented in clojurescript? Thank you in advance.

In views.cljs:

[:button {:on-click #(rf/dispatch [::events/img-one])}]

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You're probably looking for Element.scrollIntoView(). I also don't think you have to modify events.cljs, just add this code into views.cljs (I also added some images for testing):

[:button {:on-click #(.scrollIntoView
                                   (.getElementById js/document "id3"))}
             "Click me"]

[:div
  [:div [:img#id1 {:src "" :style {:width 600 :height 1000 :background "red"}}]]
  [:div [:img#id2 {:src "" :style {:width 600 :height 1000 :background "pink"}}]]
  [:div [:img#id3 {:src "" :style {:width 600 :height 1000 :background "yellow"}}]]

With argument behavior, scrolling can be smooth:

[:button {:on-click #(.scrollIntoView
                                   (.getElementById js/document "id3")
                                   (js-obj "behavior" "smooth"))}
             "Click me"]
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda