Prepare an environment according to A minimum setting to use browser REPL of ClojureScript.
Input lines of dom-example.cljs
to the REPL.
Here's a SCREEN CAST.
Enjoy!
Prepare an environment according to A minimum setting to use browser REPL of ClojureScript.
Input lines of dom-example.cljs
to the REPL.
Here's a SCREEN CAST.
Enjoy!
(.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 |