Skip to content

Commit ff5649d

Browse files
class 1 on sonic running class
1 parent 934dc6a commit ff5649d

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

classes/sonic-speed/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
<h1>Press an arrow key to move Sonic</h1>
1313
<img id="sonic-running" src="./assets/sonic-running.gif">
1414

15-
<script src="./script.js"></script>
15+
<!-- <script src="./script.js"></script> -->
16+
<script src="./script2.js"></script>
1617
</body>
1718

1819
</html>
20+

classes/sonic-speed/script.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
// Select sonicGif in DOM so we can do things to it with javascript
2-
const stepSize = 100;
2+
const stepSize = 200;
33
const sonicGif = document.getElementById('sonic-running');
44

55
// Create functions which move Sonic around page using margins
66
function moveSonicDown() {
7-
sonicGif.style.marginTop = (parseInt(window.getComputedStyle(sonicGif).marginTop) + stepSize) + 'px';
7+
const currentMarginTop = parseInt(window.getComputedStyle(sonicGif).marginTop);
8+
sonicGif.style.marginTop = (currentMarginTop + stepSize) + 'px';
89
}
910

1011
function moveSonicUp() {
11-
sonicGif.style.marginTop = (parseInt(window.getComputedStyle(sonicGif).marginTop) - stepSize) + 'px';
12+
const currentMarginTop = parseInt(window.getComputedStyle(sonicGif).marginTop);
13+
sonicGif.style.marginTop = (currentMarginTop - stepSize) + 'px';
1214
}
1315

1416
function moveSonicRight() {
15-
sonicGif.style.marginLeft = (parseInt(window.getComputedStyle(sonicGif).marginLeft) + stepSize) + 'px';
17+
const currentMarginLeft = parseInt(window.getComputedStyle(sonicGif).marginLeft);
18+
sonicGif.style.marginLeft = (currentMarginLeft + stepSize) + 'px';
1619
}
1720

1821
function moveSonicLeft() {
19-
sonicGif.style.marginLeft = (parseInt(window.getComputedStyle(sonicGif).marginLeft) - stepSize) + 'px';
22+
const currentMarginLeft = parseInt(window.getComputedStyle(sonicGif).marginLeft);
23+
sonicGif.style.marginLeft = (currentMarginLeft - stepSize) + 'px';
2024
}
2125

2226
// Add key press event listener. Only do things for arrow keys

classes/sonic-speed/style.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#sonic-running {
2-
height: 100px;
2+
height: 200px;
33
aspect-ratio: auto;
44
}
5+
6+
html {
7+
/* come back to this */
8+
background-image: url('https://stock.adobe.com/search?k=racetrack+cartoon');
9+
}

0 commit comments

Comments
 (0)