-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
103 lines (89 loc) · 3.83 KB
/
index.html
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Juego de Reciclaje</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="basuras">
<img class="basura" id="bolapapel" draggable="true" src="imagenes\bolapapel.png">
<img class="basura" id="botellaplastico" draggable="true" src="imagenes\botellaplastico.png">
<img class="basura" id="botellavidrio" draggable="true" src="imagenes\botellavidrio.png">
<img class="basura" id="carton" draggable="true" src="imagenes\carton.png">
<img class="basura" id="lata" draggable="true" src="imagenes\lata.png">
<img class="basura" id="manzana" draggable="true" src="imagenes\manzana.png">
<img class="basura" id="restoscomida" draggable="true" src="imagenes\restoscomida.png">
<img class="basura" id="servilleta" draggable="true" src="imagenes\servilleta.png">
<img class="basura" id="desechos" draggable="true" src="imagenes\desechos.png">
<img class="basura" id="metalicos" draggable="true" src="imagenes\metalicos.png">
</div>
<br>
<div id="contenedor">
<img id="cancaVerde" class="caneca" src="imagenes\verde.png" draggable="false">
<img id="cancaBlanca" class="caneca" src="imagenes\blanca.png" draggable="false">
<img id="cancaNegra" class="caneca" src="imagenes\negra.png" draggable="false">
</div>
<script>
const canecas = document.querySelectorAll('.caneca');
const basuras = document.querySelectorAll('.basura');
basuras.forEach(basura => {
basura.addEventListener('touchstart', (e) => {
e.target.style.opacity = '0.5';
e.target.classList.add('dragging');
});
basura.addEventListener('touchmove', (e) => {
e.preventDefault();
const touch = e.touches[0];
e.target.style.top = touch.clientY + 'px';
e.target.style.left = touch.clientX + 'px';
});
basura.addEventListener('touchend', (e) => {
e.target.style.opacity = '1';
e.target.classList.remove('dragging');
const caneca = document.elementFromPoint(e.changedTouches[0].clientX, e.changedTouches[0].clientY);
if (caneca && caneca.classList.contains('caneca')) {
caneca.appendChild(e.target);
}
});
});
function touchStart(e) {
e.target.style.opacity = '0.5';
}
function touchMove(e) {
e.preventDefault();
}
function touchEnd(e) {
e.target.style.opacity = '1';
}
function dragStart(e) {
e.dataTransfer.setData('text/plain', e.target.id);
e.target.style.opacity = '0.5';
}
function dragEnd(e) {
e.target.style.opacity = '1';
}
canecas.forEach(caneca => {
caneca.addEventListener('dragover', dragOver);
caneca.addEventListener('drop', drop);
caneca.addEventListener('touchenter', touchEnter);
caneca.addEventListener('touchleave', touchLeave);
});
function dragOver(e) {
e.preventDefault();
}
function drop(e) {
const idBasura = e.dataTransfer.getData('text/plain');
const basura = document.getElementById(idBasura);
e.target.appendChild(basura);
}
function touchEnter(e) {
e.target.style.border = '1px solid #ccc';
}
function touchLeave(e) {
e.target.style.border = 'none';
}
</script>
</body>
</html>