File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 12
12
< h1 > Press an arrow key to move Sonic</ h1 >
13
13
< img id ="sonic-running " src ="./assets/sonic-running.gif ">
14
14
15
- < script src ="./script.js "> </ script >
15
+ <!-- <script src="./script.js"></script> -->
16
+ < script src ="./script2.js "> </ script >
16
17
</ body >
17
18
18
19
</ html >
20
+
Original file line number Diff line number Diff line change 1
1
// Select sonicGif in DOM so we can do things to it with javascript
2
- const stepSize = 100 ;
2
+ const stepSize = 200 ;
3
3
const sonicGif = document . getElementById ( 'sonic-running' ) ;
4
4
5
5
// Create functions which move Sonic around page using margins
6
6
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' ;
8
9
}
9
10
10
11
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' ;
12
14
}
13
15
14
16
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' ;
16
19
}
17
20
18
21
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' ;
20
24
}
21
25
22
26
// Add key press event listener. Only do things for arrow keys
Original file line number Diff line number Diff line change 1
1
# sonic-running {
2
- height : 100 px ;
2
+ height : 200 px ;
3
3
aspect-ratio : auto;
4
4
}
5
+
6
+ html {
7
+ /* come back to this */
8
+ background-image : url ('https://stock.adobe.com/search?k=racetrack+cartoon' );
9
+ }
You can’t perform that action at this time.
0 commit comments