|
27 | 27 |
|
28 | 28 | <body style="height:2000px"> |
29 | 29 |
|
30 | | - Click on a field to move the ball there. |
| 30 | + Klik pada lapangan untuk memindahkan bola kesana. |
31 | 31 | <br> |
32 | 32 |
|
33 | 33 |
|
|
39 | 39 | <script> |
40 | 40 | field.onclick = function(event) { |
41 | 41 |
|
42 | | - // window-relative field coordinates |
| 42 | + // Koordinat lapangan relatif terhadap jendela (window) |
43 | 43 | let fieldCoords = this.getBoundingClientRect(); |
44 | 44 |
|
45 | | - // the ball has position:absolute, the field: position:relative |
46 | | - // so ball coordinates are relative to the field inner left-upper corner |
| 45 | + // bola memiliki position:absolute, lapangan: position:relative |
| 46 | + // jadi koordinat bola relatif terhadap sudut dalam kiri atas lapangan |
47 | 47 | let ballCoords = { |
48 | 48 | top: event.clientY - fieldCoords.top - field.clientTop - ball.clientHeight / 2, |
49 | 49 | left: event.clientX - fieldCoords.left - field.clientLeft - ball.clientWidth / 2 |
50 | 50 | }; |
51 | 51 |
|
52 | | - // prevent crossing the top field boundary |
| 52 | + // mencegah melewati batas atas lapangan |
53 | 53 | if (ballCoords.top < 0) ballCoords.top = 0; |
54 | 54 |
|
55 | | - // prevent crossing the left field boundary |
| 55 | + // mencegah melewati kiri atas lapangan |
56 | 56 | if (ballCoords.left < 0) ballCoords.left = 0; |
57 | 57 |
|
58 | 58 |
|
59 | | - // // prevent crossing the right field boundary |
| 59 | + // mencegah melewati batas kanan lapangan |
60 | 60 | if (ballCoords.left + ball.clientWidth > field.clientWidth) { |
61 | 61 | ballCoords.left = field.clientWidth - ball.clientWidth; |
62 | 62 | } |
63 | 63 |
|
64 | | - // prevent crossing the bottom field boundary |
| 64 | + // mencegah melewati batas bawah lapangan |
65 | 65 | if (ballCoords.top + ball.clientHeight > field.clientHeight) { |
66 | 66 | ballCoords.top = field.clientHeight - ball.clientHeight; |
67 | 67 | } |
|
0 commit comments