html
html
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div id = "world">
<div id = "box"></div>
</div>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
body {
}
#world{
position:relative;
border-bottom:2px solid green;
height:500px;
width:100%;
}
#box{
position:absolute;
bottom:0px;
height:100px;
width:100px;
background-color: red;
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
window.addEventListener('load',
function (){
box = document.getElementById('box');
box.addEventListener('touchmove',move);
box.addEventListener('touchend',fall);
});
var boxY,falling = false;
function move(event){
touches = event.targetTouches[0];
box.style.top
= touches.clientY -50 + "px";
box.style.left
= touches.clientX -50 + "px";
boxY = touches.clientY-50;
}
function fall(){
if(!falling){
falling = true;
let g = 0;
let i = setInterval(function(){
box.style.top = boxY + "px";
boxY += g;
if(boxY > 400){clearInterval(i); falling = false;
box.style.top = 400 + "px";
}
g += 0.1;
},1);
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run