检测点击坐标 Clojure

Detect Click Coordinates Clojure

我有以下 ClojureScript 代码,正在尝试检测点击的坐标。到目前为止,我什至无法收到 Javascript 警报来识别点击,更不用说给我坐标了。

我知道我将不得不编写一个函数,让它为我提供被点击的确切单元格,但作为开始,我需要知道如何获取页面上任何被点击区域的坐标。

谢谢!

(defn header [color text]
  [:h1
   {:style
    {:color color
     :background-color "blue"}}
   text])

(defn Cell []
  [:div
    {:style
     {:width "40px"
      :height "40px"
      :float "right"
      :margin-bottom "1px"
      :margin-right "1px"
      :background-color "grey"
      :border "1px" "solid" "white"}}])

(defn home-page []
  [:div
   [header "red" "Minesweeper"]
   [:div
    {:style
     {:width "440px"
      :height "440px"}}
    (repeat 100 [Cell])]])

:onClick 键置于与 :style 相同的地图缩进级别。它的值应该是一个函数,它会得到一个事件e。那么:

(let [coords (.getClientPosition e)
      coords' {:x (aget coords "x")
               :y (aget coords "y")}])

这是一个具有 :onClick 事件及其函数的哈希图示例:

{ :href "#"
  :onClick (fn [e]
               (.preventDefault e)
               (swap! counter inc))} 

以上唯一重要的是获取 e 并使用它。这是从 flappybird example program 中摘录的,我就是这样开始的。