-
Notifications
You must be signed in to change notification settings - Fork 1
FabricJs
Youngho Kim edited this page Nov 26, 2022
·
4 revisions
// npm install fabric @types/fabirc --save
import { fabric } from "fabric";
function FabricCanvas() {
useEffect(() => {
canvas.current = initCanvas();
// destroy fabric on unmount
return () => {
canvas.current.dispose();
canvas.current = null;
};
}, []);
const initCanvas = () =>
new fabric.Canvas("canvas", {
height: 800,
width: 800,
backgroundColor: "pink",
});
return (<>
<canvas id="canvas" />
</>
);
}
const rect = new fabric.Rect({
height: 280,
width: 200,
top: 100,
left: 100,
fill: "yellow",
});
canvas.currnet.add(rect)
const rect = new fabric.Rect({
height: 280,
width: 200,
top: 100,
left: 100,
fill: "yellow",
});
rect.get('์์ฑ') //ex) height, widht, top, left...
const rect = new fabric.Rect({
height: 280,
width: 200,
top: 100,
left: 100,
fill: "yellow",
});
rect.set('์์ฑ', value)
const rect = new fabric.Rect({
height: 280,
width: 200,
top: 100,
left: 100,
fill: "yellow",
});
canvas.currnet.remove(rect)
canvas.current.on("eventname", callback);
- Canvas Event ์ข
๋ฅ
- object:modified at the end of a transform or any change when statefull is true
- object:rotating while an object is being rotated from the control
- object:scaling while an object is being scaled by controls
- object:moving while an object is being dragged
- object:skewing while an object is being skewed from the controls
- before:transform before a transform is is started
- before:selection:cleared
- selection:cleared
- selection:updated
- selection:created
- path:created after a drawing operation ends and the path is added
- mouse:down
- mouse:move
- mouse:up
- mouse:down:before on mouse down,event: before the inner fabric logic runs
- mouse:move:before on mouse move,event: before the inner fabric logic runs
- mouse:up:before on mouse up,event: before the inner fabric logic runs
- mouse:over
- mouse:out
- mouse:dblclick whenever a native dbl click event fires on the canvas.
- event:dragover
- event:dragenter
- event:dragleave
- drop:before before drop event. same native event.event: This is added to handle edge cases
- event:drop
- after:render at the end of the render process,event: receives the context in the callback
- before:render at start the render process,event: receives the context in the callback
const rect = new fabric.Rect({
height: 280,
width: 200,
top: 100,
left: 100,
fill: "yellow",
});
rect.on("eventname", callback);
- Object Event ์ข
๋ฅ
- event:added
- event:removed
- event:selected
- event:deselected
- event:modified
- event:modified
- event:moved
- event:scaled
- event:rotated
- event:skewed
- event:rotating
- event:scaling
- event:moving
- event:skewing
- event:mousedown
- event:mouseup
- event:mouseover
- event:mouseout
- event:mousewheel
- event:mousedblclick
- event:dragover
- event:dragenter
- event:dragleave
- event:drop
์ฐธ๊ณ :
[Working with events ยท fabricjs/fabric.js Wiki](https://github.com/fabricjs/fabric.js/wiki/Working-with-events)
object.set({
borderColor: 'red',
cornerColor: 'black'
});
new fabric.Canvas("canvas", {
height: 800,
width: 800,
backgroundColor: "pink",
isDrawingMode: true,
});
๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week1-Day1] ํ ๋น๋ฉ
- [Week1-Day2] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week1-Day3] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week1-Day4] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week1-Day5] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week2-Day1] ์คํ๋ฆฐํธ ๊ณํ ํ์
- [Week2-Day2] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week2-Day3] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week2-Day4] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week3-Day1] ์คํ๋ฆฐํธ ๊ณํ ํ์
- [Week3-Day2] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week3-Day3] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week3-Day4] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week4-Day1] ์คํ๋ฆฐํธ ๊ณํ ํ์
- [Week4-Day2] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week4-Day3] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week4-Day4] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week5-Day1] ์คํ๋ฆฐํธ ๊ณํ ํ์
- [Week5-Day2] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week5-Day3] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week5-Day4] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week6-Day1] ์คํ๋ฆฐํธ ๊ณํ ํ์
- [Week6-Day2] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week6 Day3] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ
- [Week6 Day4] ๋ฐ์ผ๋ฆฌ ์คํฌ๋ผ