Binding Fabric.js to data #1078
Answered
by
fonsp
gragusa
asked this question in
Questions about using Pluto
-
I am trying to create a UI using Fabric.js. I have DrawingCanvas() = @htl("""
<div id="parent">
<canvas id="sheet" width="400" height="400"></canvas>
<button id="clear">Clear</button>
<button id="guess">Guess</button>
</div>
<script type='text/javascript' src='http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.4.0/fabric.min.js'></script>
<script type='text/javascript'>
const pDiv = currentScript.closest('pluto-output').querySelector("div#parent")
var clear = pDiv.querySelector("#clear")
var guess = pDiv.querySelector("#guess")
var canvas = new fabric.Canvas('sheet');
canvas.isDrawingMode = true;
canvas.freeDrawingBrush.width = 5;
canvas.freeDrawingBrush.color = "#000000";
var href = "";
guess.addEventListener("click", (e) => {
href = canvas.toDataURL({
format: 'png'
}).toString();
pDiv.value = href;
pDiv.dispatchEvent(new CustomEvent("input"));
console.log(href)
console.log(pDiv.value)
})
pDiv.value = href;
clear.addEventListener("click", (e) => {
canvas.clear();
pDiv.value="";})
</script>
""") Everything works, except (big exception) the binding of |
Beta Was this translation helpful? Give feedback.
Answered by
fonsp
Apr 12, 2021
Replies: 1 comment 3 replies
-
What exactly is the problem/error? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
fonsp
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What exactly is the problem/error?