Skip to content

Commit a8fe8fc

Browse files
author
Greg Pfaff
committed
JS 30 updates
1 parent 8e254bd commit a8fe8fc

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

08 - Fun with HTML5 Canavsa/index-START.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,67 @@
77
<body>
88
<canvas id="draw" width="800" height="800"></canvas>
99
<script>
10+
11+
const canvas = document.querySelector('#draw');
12+
13+
const ctx = canvas.getContext('2d');
14+
15+
canvas.width = window.innerWidth;
16+
canvas.height = window.innerHeight;
17+
18+
ctx.strokeStyle = '#BADA55';
19+
ctx.lineJoin = 'round';
20+
ctx.lineCap = 'round';
21+
ctx.lineWidth = '20';
22+
23+
let isDrawing = false;
24+
let lastX = 0;
25+
let lastY = 0;
26+
let hue = 0;
27+
let direction = true;
28+
29+
function draw(event) {
30+
if (!isDrawing) return;
31+
console.log(event);
32+
33+
ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`;
34+
ctx.beginPath();
35+
ctx.moveTo(lastX, lastY);
36+
ctx.lineTo(event.offsetX, event.offsetY);
37+
ctx.stroke();
38+
hue++;
39+
40+
if (hue >= 360) {
41+
hue = 0;
42+
}
43+
44+
if (ctx.lineWidth >= 100 || ctx.lineWidth <= 1) {
45+
direction = !direction;
46+
}
47+
48+
if (direction) {
49+
ctx.lineWidth++
50+
} else {
51+
ctx.lineWidth--;
52+
}
53+
54+
[lastX, lastY] = [event.offsetX, event.offsetY]
55+
}
56+
57+
58+
59+
canvas.addEventListener('mousemove', draw);
60+
canvas.addEventListener('mousedown', (event) => {
61+
isDrawing = true,
62+
[lastX, lastY] = [event.offsetX, event.offsetY];
63+
});
64+
canvas.addEventListener('mouseout', () => isDrawing = false);
65+
canvas.addEventListener('mouseup', () => isDrawing = false);
66+
67+
68+
69+
70+
1071
</script>
1172

1273
<style>

09 - Dev Tools Domination/index-START.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</head>
77
<body>
88

9-
<p onClick="makeGreen()">×BREAK×DOWN×</p>
9+
<p onclick="makeGreen()">×BREAK×DOWN×</p>
1010

1111
<script>
1212
const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }];

10 - Hold Shift and Check Checkboxes/index-START.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@
104104
</div>
105105

106106
<script>
107+
const checkBoxes = Array.from(document.getElementsByTagName('input'));
108+
let checked = false;
109+
console.log(checkBoxes);
110+
111+
checkBoxes.forEach((checkbox) => {
112+
console.log(checkbox);
113+
checkbox.addEventListener('click', (event) => {
114+
if ('input') {
115+
checkbox.setAttribute('data-value', 'checked');
116+
} else {
117+
checkbox.removeAttribute('data-value', 'checked');
118+
}
119+
})
120+
});
121+
122+
123+
// checkBoxes.addEventListener('click', (event) => {
124+
// if ('input:checked') {
125+
// console.log('Checked');
126+
// }
127+
// })
128+
129+
console.log(checkBoxes);
130+
131+
107132
</script>
108133
</body>
109134
</html>

0 commit comments

Comments
 (0)