Skip to content

Commit 578cf59

Browse files
committed
image loading test
1 parent ed4421f commit 578cf59

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/App.jsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,28 @@ function App() {
137137
top={"30%"}
138138
display={{ base: "none", lg: "block" }}
139139
></Box>
140-
<Image
141-
src="/boximage.png"
140+
{/* 使用 picture 元素提供多种格式 */}
141+
<Box
142142
w={{ base: "280px", md: "400px", lg: "640px" }}
143143
h={{ base: "280px", md: "400px", lg: "640px" }}
144144
position={{ base: "static", lg: "absolute" }}
145-
objectFit="contain"
146-
/>
145+
>
146+
<picture>
147+
<source srcSet="/boximage.webp" type="image/webp" />
148+
<source srcSet="/boximage.avif" type="image/avif" />
149+
<Image
150+
src="/boximage.png"
151+
alt="Profile image"
152+
w="100%"
153+
h="100%"
154+
objectFit="contain"
155+
loading="eager"
156+
opacity={imageLoaded ? 1 : 0}
157+
transition="opacity 0.3s ease"
158+
fallbackSrc="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjQwMCIgdmlld0JveD0iMCAwIDQwMCA0MDAiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSI0MDAiIGhlaWdodD0iNDAwIiBmaWxsPSIjRjNGNEY2Ii8+CjxjaXJjbGUgY3g9IjIwMCIgY3k9IjIwMCIgcj0iNTAiIGZpbGw9IiNEMUQ1REIiLz4KPC9zdmc+"
159+
/>
160+
</picture>
161+
</Box>
147162
<Flex>
148163
<VStack
149164
transform={{ base: "none", lg: "translate(120px,100px)" }}

0 commit comments

Comments
 (0)