-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
95 lines (66 loc) · 2.24 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
alert("Please upvote if you like\n")
//console.log("hello from js");
/*fetch("https://dog.ceo/api/breeds/list/all")
.then( response => response.json())
.then( data => {
console.log(data);
})*/
let timer;
let deleteFirstPhotoDelay;
async function start(){
const response = await fetch("https://dog.ceo/api/breeds/list/all")
const data = await response.json()
//console.log(data)
createBreedList(data.message)
}
start()
function createBreedList(breedList){
document.getElementById("breed").innerHTML=`
<select onchange="loadByBreed(this.value)">
<option>Choose Dog Breed</option>
${Object.keys(breedList).map(function (breed) {
return `<option>${breed}</option>`;
}).join("")}
</select>
`;
}
async function loadByBreed(breed){
if(breed != "Choose Dog Breed"){
const response = await fetch(`https://dog.ceo/api/breed/${breed}/images`)
const data = await response.json()
createSlideShow(data.message)
}
}
function createSlideShow(images){
let currentPosition=0;
clearInterval(timer)
clearTimeout(deleteFirstPhotoDelay)
//document.getElementById('slideshow').innerHTML=
//console.log(`<div class="slide" style="background-image:url('${images[1]}')">
//</div>`)
if(images.length>1){
document.getElementById("slideshow").innerHTML=`<div class="slide"><img src="${images[0]}" alt="dog1"></div>
`
currentPosition+=2;
//if(currentPosition==2) currentPosition=0;
timer=setInterval(nextSlide , 3000)
}
/*else{
document.getElementById("slideshow").innerHTML=`<div class="slide"><img src="${images[0]}" alt="dog1"></div>
<div class="slide"></div>
`
}*/
function nextSlide(){
document.getElementById("slideshow").insertAdjacentHTML('beforeend', `<div class="slide"><img src="${images[currentPosition]}" alt="dog1"></div>`);
deleteFirstPhotoDelay=setTimeout(function () {
document.querySelector(".slide").remove()
}, 1000);
if(currentPosition+1>=images.length){
currentPosition=0;
}
else{
currentPosition++;
}
}
}
//created by Rankush