Skip to content

Instantly share code, notes, and snippets.

@kohyama kohyama/README.md
Last active Mar 3, 2018

Embed
What would you like to do?
Example to operate DOM in ClojureScript via Browser REPL
(.log js/console "Hello JavaScript Console!")
(js/alert "Hello JavaScript in a page!")
(ns foo (:require [clojure.browser.dom :as dom]))
(def pane (dom/element :div))
(dom/append (.-body js/document) pane)
(def ta (dom/element :textarea {:cols 80 :rows 10}))
(dom/append pane ta)
(dom/set-value ta "Hello textarea from REPL!")
(dom/set-value ta "Hello textarea from REPL!\nYou can operate DOM elements from your REPL")
(dom/append pane (dom/element :br))
(dom/append pane (dom/element :input {:type "text" :value "One more example"}))
(set! (.-id pane) "pane")
(dom/remove-children "pane")
(def cvs (dom/element :canvas {:width 100 :height 100}))
(set! (.-border (.-style cvs)) "dotted 3px blue"))
(dom/append pane cvs)
(set! (.-border (.-style cvs)) "solid 1px black"))
(set! (.-width cvs) 320)
(set! (.-height cvs) 240)
(def ctx (.getContext cvs "2d"))
(set! (.-fillStyle ctx) "rgb(255,0,0)")
(.beginPath ctx)
(.arc ctx 160 120 72 0.0 (* 2.0 Math/PI) false)
(.fill ctx)
:cljs/quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.