Skip to content

Commit aa46653

Browse files
committed
feat: create progressive image loading
1 parent 4b2892a commit aa46653

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

public/image/header-bg-low.jpg

76 KB
Loading

public/image/header-bg.jpg

1.56 MB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useState, useRef } from "react";
2+
3+
function ProgressiveImage(props){
4+
const [highResImageLoaded, handlehighResImageLoaded] = useState(false);
5+
const highResImage = useRef(null);
6+
7+
const overlayStyles = {
8+
position: "absolute",
9+
filter: "blur(1px)",
10+
transition: "opacity ease-in 1000ms",
11+
clipPath: "inset(0)"
12+
};
13+
const { overlaySrc, alt, src } = props;
14+
return (
15+
<span>
16+
<img
17+
onLoad={() => {
18+
handlehighResImageLoaded(true)
19+
}}
20+
ref={highResImage}
21+
src={src}
22+
alt={alt}
23+
/>
24+
<img
25+
className={` ${overlayStyles}`}
26+
{...highResImageLoaded && { style: { opacity: "0" } }}
27+
src={overlaySrc}
28+
alt={alt}
29+
/>
30+
</span>
31+
);
32+
}
33+
34+
export default ProgressiveImage;

src/components/header/header.style.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import theme from '../../style/theme';
33

44
const HeaderStyle = style.div`
55
height: 80vh;
6-
background: url("https://phandroid.s3.amazonaws.com/wp-content/uploads/2014/05/rainbow-nebula.jpg") repeat;
6+
background: url("/image/header-bg.jpg") repeat;
77
background-size: cover;
88
background-position: bottom;
99
position: relative;

0 commit comments

Comments
 (0)