Skip to content

Commit 0a71767

Browse files
committed
Shake now shakes the entire Wes-a-sketch
1 parent 93b51c5 commit 0a71767

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

33 - Etch-a-Sketch/etch-a-sketch.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
// Select the elements on the page - canvas, shake button
22
const canvas = document.querySelector('#etch-a-sketch');
33
const ctx = canvas.getContext('2d');
4-
const shakebutton = document.querySelector('.shake');
4+
const shakebutton = document.querySelector('#shake');
55
const MOVE_AMOUNT = 10;
66
const slider = document.querySelector('.slider');
77
const background = document.querySelector('.wes-a-sketch');
88
const rainbowButton = document.querySelector('.rainbow');
99
let rainbowMode = false;
1010
const CANVAS_BACKGROUND = '212, 217, 221';
11-
const DEFAULT_STROKE_COLOR = '#515054'
11+
const DEFAULT_STROKE_COLOR = '#515054';
12+
const knobs = document.querySelectorAll('.knob');
1213

1314
// Setup our canvas for drawing
1415
// Make variables called height and width from the same properties on our canavas
@@ -126,6 +127,10 @@ function handleKey(e) {
126127
function clearCanvas() {
127128
canvas.classList.add('shake');
128129
background.classList.add('shake');
130+
shakebutton.classList.add('shake');
131+
rainbowButton.classList.add('shake');
132+
slider.classList.add('shake');
133+
knobs.forEach(knob => knob.classList.add('shake'));
129134

130135
// Gradually shake away the drawing. Takes 3-4 shakes.
131136
ctx.fillStyle = `rgba(${CANVAS_BACKGROUND}, 0.8)`
@@ -139,6 +144,10 @@ function clearCanvas() {
139144
function() {
140145
canvas.classList.remove('shake');
141146
background.classList.remove('shake');
147+
shakebutton.classList.remove('shake');
148+
rainbowButton.classList.remove('shake');
149+
slider.classList.remove('shake');
150+
knobs.forEach(knob => knob.classList.remove('shake'));
142151
},
143152
{ once: true }
144153
);

33 - Etch-a-Sketch/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1>Magic <strong>Wes-a-Sketch</strong> Screen</h1>
2020
<div class="knob left-knob"></div>
2121
<div class="buttons">
2222
<input type="range" min="1" max="100" value="10" class="slider">
23-
<button class="shake">Shake!</button>
23+
<button id="shake">Shake!</button>
2424
<button class="rainbow">🌈</button>
2525
</div>
2626
<div class="knob right-knob"></div>
@@ -84,7 +84,10 @@ <h1>Magic <strong>Wes-a-Sketch</strong> Screen</h1>
8484
}
8585

8686
canvas.shake,
87-
div.wes-a-sketch.shake {
87+
div.wes-a-sketch.shake,
88+
div.knob.shake,
89+
input.shake,
90+
button.shake {
8891
animation: shake 0.5s linear 1;
8992
}
9093

0 commit comments

Comments
 (0)