Created
October 1, 2021 11:02
-
-
Save php1301/e902f6a8367a6815fa78e2348452b78c to your computer and use it in GitHub Desktop.
shimmer nextjs 11+
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export const shimmer = (w, h) => ` | |
| <svg width="${w}" height="${h}" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> | |
| <defs> | |
| <linearGradient id="g"> | |
| <stop stop-color="#cfcfcf" offset="20%" /> | |
| <stop stop-color="#fff" offset="50%" /> | |
| <stop stop-color="#fff" offset="70%" /> | |
| </linearGradient> | |
| </defs> | |
| <rect width="${w}" height="${h}" fill="#cfcfcf" /> | |
| <rect id="r" width="${w}" height="${h}" fill="url(#g)" /> | |
| <animate xlink:href="#r" attributeName="x" from="-${w}" to="${w}" dur="1s" repeatCount="indefinite" /> | |
| </svg>`; | |
| export const toBase64 = (str) => | |
| typeof window === "undefined" | |
| ? Buffer.from(str).toString("base64") | |
| : window.btoa(str); | |
| /* className="blog-lazyload-image h-full"> | |
| <Image | |
| className="w-full h-full object-cover" | |
| alt="blog" | |
| layout="fill" | |
| placeholder="blur" | |
| blurDataURL={`data:image/svg+xml;base64,${toBase64( | |
| shimmer(565, 275), | |
| )}`} | |
| src={ | |
| blog?.thumbnail || placeholderImage | |
| } | |
| /> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment