Created
January 22, 2020 20:08
-
-
Save bobbicodes/23f2cde981e09d2d82a8c0881867376f to your computer and use it in GitHub Desktop.
use svg file in reagent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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