Skip to content

Instantly share code, notes, and snippets.

@bobbicodes
Created January 22, 2020 20:08
Show Gist options
  • Save bobbicodes/23f2cde981e09d2d82a8c0881867376f to your computer and use it in GitHub Desktop.
Save bobbicodes/23f2cde981e09d2d82a8c0881867376f to your computer and use it in GitHub Desktop.
use svg file in reagent
(defn foo []
;; with this code you can access all your svg elements in JS
[:object
{:data "/file.svg"
:id "file"
:width ...
:height ...}
;; make sure you access the elements only when the svg has fully loaded
:onLoad (fn []
(let [svg-content (.-contentDocument
(js/document.getElementById "file"))]
;; now you can normally access your svg elements in JS and
;; perform any operation i.e.
(set! (-> (.getElementById svg-content "my-svg-element-id")
.-style .-fill) "red")
...
))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment