x-intersect
Browse files- index.html +7 -18
index.html
CHANGED
@@ -5,7 +5,8 @@
|
|
5 |
<meta name="viewport" content="width=device-width" />
|
6 |
<title>Diffusers gallery</title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
-
<script defer
|
|
|
9 |
|
10 |
<script>
|
11 |
function getModels(page) {
|
@@ -21,16 +22,7 @@
|
|
21 |
function findImage(text) {
|
22 |
const imageRegex = /(https?:\/\/.*\.(?:png|jpg))(\?.*)?/i;
|
23 |
const match = text.match(imageRegex);
|
24 |
-
return match ? match[
|
25 |
-
}
|
26 |
-
|
27 |
-
function onIntersection(targetEl, callback) {
|
28 |
-
const observer = new IntersectionObserver(([entry]) => {
|
29 |
-
if (entry.isIntersecting) {
|
30 |
-
callback();
|
31 |
-
}
|
32 |
-
});
|
33 |
-
observer.observe(targetEl);
|
34 |
}
|
35 |
</script>
|
36 |
</head>
|
@@ -39,18 +31,15 @@
|
|
39 |
<section
|
40 |
class="container px-6 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 mx-auto"
|
41 |
x-data="{models: [], page: 0}"
|
42 |
-
x-init="models = await getModels()
|
43 |
-
|
44 |
-
models = [...models, ...await getModels(page+1)]
|
45 |
-
page++;
|
46 |
-
})"
|
47 |
>
|
48 |
<template x-for="model in models" :key="model.id">
|
49 |
<a
|
50 |
x-data="{img: null}"
|
51 |
x-init="img = await getModelCard(model.id).then(findImage)"
|
52 |
:href="`https://huggingface.co/${model.id}`"
|
53 |
-
class="block bg-gray-
|
54 |
target="_blank"
|
55 |
>
|
56 |
<div
|
@@ -86,7 +75,7 @@
|
|
86 |
</div>
|
87 |
</a>
|
88 |
</template>
|
89 |
-
<div class="h-12" x-
|
90 |
</section>
|
91 |
</body>
|
92 |
</html>
|
|
|
5 |
<meta name="viewport" content="width=device-width" />
|
6 |
<title>Diffusers gallery</title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
+
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/intersect@3.x.x/dist/cdn.min.js"></script>
|
9 |
+
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
10 |
|
11 |
<script>
|
12 |
function getModels(page) {
|
|
|
22 |
function findImage(text) {
|
23 |
const imageRegex = /(https?:\/\/.*\.(?:png|jpg))(\?.*)?/i;
|
24 |
const match = text.match(imageRegex);
|
25 |
+
return match ? match[0] : null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
</script>
|
28 |
</head>
|
|
|
31 |
<section
|
32 |
class="container px-6 grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 mx-auto"
|
33 |
x-data="{models: [], page: 0}"
|
34 |
+
x-init="models = await getModels()"
|
35 |
+
x-effect="console.log(models)"
|
|
|
|
|
|
|
36 |
>
|
37 |
<template x-for="model in models" :key="model.id">
|
38 |
<a
|
39 |
x-data="{img: null}"
|
40 |
x-init="img = await getModelCard(model.id).then(findImage)"
|
41 |
:href="`https://huggingface.co/${model.id}`"
|
42 |
+
class="block bg-gray-900 rounded-xl overflow-hidden relative group aspect-square"
|
43 |
target="_blank"
|
44 |
>
|
45 |
<div
|
|
|
75 |
</div>
|
76 |
</a>
|
77 |
</template>
|
78 |
+
<div class="h-12" x-intersect="models = [...models, ...await getModels(page+1)]; page++"></div>
|
79 |
</section>
|
80 |
</body>
|
81 |
</html>
|