Skip to content

Commit ec07166

Browse files
committed
Add intersection observer
1 parent e32d2e5 commit ec07166

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/shared/ui/Card/Card.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
1+
import { createEffect } from "solid-js"
12
import Button from "~/shared/ui/Button"
23
import Price from "~/shared/ui/Price"
34

45
export type Props = { title: string; timer: string; bid: number; img: string }
56

67
const Card = (props: Props) => {
8+
let ref: HTMLImageElement
9+
10+
createEffect(() => {
11+
const options = {}
12+
const observer = new IntersectionObserver((entries, observer) => {
13+
for (const entry of entries) {
14+
if (entry.isIntersecting) {
15+
ref!.style.visibility = "visible"
16+
} else {
17+
ref!.style.visibility = "hidden"
18+
}
19+
}
20+
}, options)
21+
observer.observe(ref!)
22+
})
23+
724
return (
825
<div class="p-[10px] xl:p-[14px] flex flex-col bg-white w-[200px] xl:w-[280px] rounded-3xl gap-[18px]">
926
<div class="relative aspect-square w-full">
1027
<img
28+
ref={ref!}
1129
src={`/divesea/images/${props.img}`}
1230
class="object-cover w-full aspect-square rounded-3xl"
1331
loading="lazy"

0 commit comments

Comments
 (0)