html
html
1
2
3
4
5
6
7
8
9
10
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div id="div"></div>
<button onclick="test?test=false:test=true">Stop/Start</button>
</body>
</html>
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
5
6
7
8
9
10
body {
user-select:none;
overflow:hidden;
}
#div{
width:100px;
height:100px;
position:absolute;
background-color:pink;
}
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
var test = true
var mousedown = false
window.onload = () => {
const div = document.getElementById("div")
var left = 0
var top = 0
div.addEventListener("touchmove",function(e){
if(test){
this.style.left = e.targetTouches[0].pageX - left + "px"
this.style.top = e.targetTouches[0].pageY - top + "px"
}
})
div.addEventListener("touchstart",function(e){
if(test){
left = e.targetTouches[0].pageX - this.getBoundingClientRect().left
top = e.targetTouches[0].pageY - this.getBoundingClientRect().top
}
})
div.addEventListener("mousemove",function(e){
if(test && mousedown){
this.style.left = e.pageX - left + "px"
this.style.top = e.pageY - top + "px"
}
})
document.body.addEventListener("mousedown",function(e){
if(test){
left = e.pageX - div.getBoundingClientRect().left
top = e.pageY - div.getBoundingClientRect().top
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run