-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
186 lines (178 loc) · 8.51 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<html>
<head>
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<h1 align="center">Meme Generator</h1>
<!--- <img id="img1" src="https://i.gifer.com/33Ho.gif" class="img-fluid rounded mx-auto d-block" alt="meme" height="50%">
<div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-indicators">
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active" aria-current="true" aria-label="Slide 1"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1" aria-label="Slide 2"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2" aria-label="Slide 3"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="3" aria-label="Slide 4"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="4" aria-label="Slide 5"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="5" aria-label="Slide 6"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="6" aria-label="Slide 7"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="7" aria-label="Slide 8"></button>
<button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="8" aria-label="Slide 8"></button>
</div>
<div id="carouselHero" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active" data-bs-interval="10000">
<img id="img0" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item" data-bs-interval="2000">
<img id="img1" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item ">
<img id="img2" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img id="img3" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item">
<img id="img4" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item ">
<img id="img5" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item ">
<img id="img6" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item ">
<img id="img7" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
<div class="carousel-item ">
<img id="img8" src="https://i.gifer.com/33Ho.gif" class="d-block w-100" alt="...">
</div>
</div>
</div>
<br/><br/>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
</div>
-->
<div id="card-container"></div>
<div id="loader">
<div class="skeleton-card"></div>
<div class="skeleton-card"></div>
<div class="skeleton-card"></div>
</div>
<div class="card-actions">
<span>Showing
<span id="card-count"></span> of
<span id="card-total"></span> cards
</span>
</div>
</body>
<script type="text/javascript">
async function memegenerator(){
for(let i=0;i<=8;i++){
let response =await fetch('https://meme-api.com/gimme');
console.log(response);
let json =await (response.json());
console.log(json.url);
if(json){
document.getElementById("img"+i).src= json.url;
}
response =null;
await new Promise(resolve => setTimeout(resolve, 1));
}
}
memegenerator();
const cardContainer = document.getElementById("card-container");
const cardCountElem = document.getElementById("card-count");
const cardTotalElem = document.getElementById("card-total");
const loader = document.getElementById("loader");
const cardLimit = 99;
cardTotalElem.innerHTML = cardLimit;
const cardIncrease = 9;
const pageCount = Math.ceil(cardLimit / cardIncrease);
let currentPage = 1;
const getRandomColor = () => {
const h = Math.floor(Math.random() * 360);
return `hsl(${h}deg, 90%, 85%)`;
};
const createCard = (index) => {
const card = document.createElement("div");
card.className = "card";
let newImg = document.createElement('img');
newImg.src = 'https://i.gifer.com/33Ho.gif';
newImg.setAttribute("data-toggle","lightbox");
async function singleimage(){
let response =await fetch('https://meme-api.com/gimme');
console.log(response);
let json =await (response.json());
console.log(json.url);
if(json){
return json.url;
}
response =null;
// await new Promise(resolve => setTimeout(resolve, 1));
}
const downloadImageAndSetSource = async () => {
const image = await singleimage();
newImg.src=image;
newImg.setAttribute("data-remote",image);
newImg.setAttribute("class","img-fluid");
newImg.style.height = "40vh";
newImg.style.width = "calc((100% / 3)+16px)";
}
downloadImageAndSetSource();
//newImg.src=singleimage();
card.appendChild(newImg);
// card.innerHTML = index;
card.style.backgroundColor = getRandomColor();
cardContainer.appendChild(card);
};
const addCards = (pageIndex) => {
currentPage = pageIndex;
const startRange = (pageIndex - 1) * cardIncrease;
const endRange = currentPage == pageCount ? cardLimit : pageIndex * cardIncrease;
cardCountElem.innerHTML = endRange;
for (let i = startRange + 1; i <= endRange; i++) {
createCard(i);
}
};
window.onload = function () {
addCards(currentPage);
};
var throttleTimer;
const throttle = (callback, time) => {
if (throttleTimer) return;
throttleTimer = true;
setTimeout(() => {
callback();
throttleTimer = false;
}, time);
};
const handleInfiniteScroll = () => {
throttle(() => {
const endOfPage =
window.innerHeight + window.pageYOffset >= document.body.offsetHeight;
if (endOfPage) {
addCards(currentPage + 1);
}
if (currentPage === pageCount) {
removeInfiniteScroll();
}
}, 1000);
};
window.addEventListener("scroll", handleInfiniteScroll);
const removeInfiniteScroll = () => {
loader.remove();
window.removeEventListener("scroll", handleInfiniteScroll);
};
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bs5-lightbox@1.8.3/dist/index.bundle.min.js"></script>
</html>