-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
101 lines (98 loc) · 3.43 KB
/
script.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
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
let contador;
let Nombre;
let Sprite;
window.onload = function() {
//document.body.style.zoom="80%"
hide();
for (let i = 1; i <= 17; i++) {
// Get the element
var elem = document.querySelector('#Ball');
var clone = elem.cloneNode(true);
clone.id = 'elem2';
clone.classList.add('text-large');
// Inject it into the DOM
elem.after(clone);
contador = i;
}
getName();
};
//Al momento de pasar el mouse por encima del boton, oscurecer el color del boton.
function oscurecer() {
document.getElementById("container4").style.backgroundColor = "#b7b7b7";
document.getElementById("container4").style.cursor = "pointer";
}
//Al momento de quitar el mouse del boton, mostrar el color original del boton.
function mostrar() {
document.getElementById("container4").style.backgroundColor = "#2174e0";
}
//Funcion que se ejecuta al pulsar el boton.
function myMove() {
document.getElementById("Pokemon").src = "";
if(contador > 0){
removeImage("elem2");
contador--;
}
else{
document.getElementById("Ball").style.display = "none";
}
document.getElementById("premio").style.display = "block";
let id = null;
const elem = document.getElementById("premio");
let pos = 580;
clearInterval(id);
id = setInterval(frame, 5);
function frame() {
if (pos == 620) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + "px";
}
}
getName();
setTimeout(function(){
document.getElementById("Pokemon").src = Sprite;
document.getElementById("NombrePkmn").innerHTML = Nombre;
}, 1700);
setTimeout(hide, 1700);
Animation = setInterval(function(){document.getElementById("pokemon").style.animation = "pokemon-animation 1s";}, 1500);
}
//Funcion para refrescar la pagina al presionar el boton.
function refresh() {
location.reload();
}
//Al momento de pasar el mouse por encima del boton, oscurecer el color del boton.
function oscurecerF5() {
document.getElementById("F5").style.backgroundColor = "#b7b7b7";
document.getElementById("F5").style.cursor = "pointer";
}
//Al momento de quitar el mouse del boton, mostrar el color original del boton.
function mostrarF5() {
document.getElementById("F5").style.backgroundColor = "#2174e0";
}
function removeImage(id) {
var elementToBeRemoved = document.getElementById(id);
elementToBeRemoved.parentNode.removeChild(elementToBeRemoved);
}
//Onclick release button hide the pokemon div.
function hide() {
document.getElementById("premio").style.display = "none";
}
//Funcion que obtiene el nombre del pokemon y lo guarda en la variable Nombre.
function getName() {
document.getElementById("NombrePkmn").innerHTML = "";
//Realiza un random entre 1 y 649.
let random = Math.floor(Math.random() * 649) + 1;
Nombre = "https://pokeapi.co/api/v2/pokemon/" + random;
//fetch de la url para obtener el nombre del pokemon.
fetch(Nombre)
.then(function(response) {
return response.json();
})
.then(function(myJson) {
Nombre = myJson.name;
//Cambia a mayusculas el nombre del pokemon.
Nombre = Nombre.charAt(0).toUpperCase() + Nombre.slice(1);
})
Sprite = "https://unpkg.com/[email protected]/sprites/pokemon/other/dream-world/" + random + ".svg";
}