-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
35 lines (28 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var canvas = document.getElementById("draw");
var ctx = canvas.getContext("2d");
let color = "#000";
let brushthickness = 7;
document.querySelector(".color-btn div").style.backgroundColor = color;
//*************************************************************************************************
//******************************************* RESIZE CANVAS ***************************************
//*************************************************************************************************
function resize() {
ctx.canvas.width = window.innerWidth - 20;
ctx.canvas.height = window.innerHeight;
}
resize();
//*************************************************************************************************
//************************************** DOWNLOAD CANVAS ******************************************
//*************************************************************************************************
function onSave() {
const link = document.createElement('a');
link.download = 'sketch.png';
link.href = canvas.toDataURL();
link.click();
link.delete;
}
//*************************************************************************************************
//***************************************** EVENT LISTENERS ***************************************
//*************************************************************************************************
// add window event listener to trigger when window is resized
window.addEventListener("resize", resize);