Skip to content

Commit a07b128

Browse files
committed
懒加载图片组件
1 parent fb96bc7 commit a07b128

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Diff for: components/LazyImage.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export default function LazyImage({
4141
if (typeof onLoad === 'function') {
4242
onLoad() // 触发传递的onLoad回调函数
4343
}
44+
// 移除占位符类名
45+
if (imageRef.current) {
46+
imageRef.current.classList.remove('lazy-image-placeholder')
47+
}
4448
}
4549
/**
4650
* 图片加载失败回调
@@ -53,6 +57,7 @@ export default function LazyImage({
5357
} else {
5458
imageRef.current.src = defaultPlaceholderSrc
5559
}
60+
imageRef.current.classList.remove('lazy-image-placeholder')
5661
}
5762
}
5863

@@ -141,15 +146,14 @@ export default function LazyImage({
141146
<style>
142147
{`
143148
.lazy-image-placeholder{
144-
145-
background:
146-
linear-gradient(90deg,#0001 33%,#0005 50%,#0001 66%)
147-
#f2f2f2;
148-
background-size:300% 100%;
149-
animation: l1 1s infinite linear;
150-
}
151-
@keyframes l1 {
152-
0% {background-position: right}
149+
background:
150+
linear-gradient(90deg,#0001 33%,#0005 50%,#0001 66%)
151+
#f2f2f2;
152+
background-size:300% 100%;
153+
animation: l1 1s infinite linear;
154+
}
155+
@keyframes l1 {
156+
0% {background-position: right}
153157
}
154158
`}
155159
</style>

Diff for: themes/magzine/components/PostItemCardSimple.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import CategoryItem from './CategoryItem'
88
* @param {*} param0
99
* @returns
1010
*/
11-
const PostItemCardSimple = ({ post, showSummary }) => {
11+
const PostItemCardSimple = ({ post }) => {
1212
return (
1313
<div
1414
key={post.id}

0 commit comments

Comments
 (0)