简体   繁体   English

是否可以使 Next.js 图像占位符不模糊?

[英]Is it possible to make Next.js Image placeholder without blur?

I'm using Next.js for my projects.我在我的项目中使用 Next.js。 Next.js Image component has placeholder and blurDataURL attrs and this combination works very well, but if I want to add my custom placeholder from SVG (SVG->base64) I got blured result. Next.js 图像组件具有占位符和 blurDataURL 属性,这种组合效果很好,但是如果我想从 SVG (SVG->base64) 添加我的自定义占位符,我会得到模糊的结果。

All my attempts to find information for disabling blur effect was failed... Anybody could help me?我所有寻找禁用模糊效果信息的尝试都失败了......有人可以帮助我吗? Thanks in advance!提前致谢!

next/image default placeholder is empty (blur off), if you want to put something as a placeholder while the images load you can add a class to the component something like next/image 默认占位符为空(关闭模糊),如果您想在加载图像时将某些内容作为占位符,您可以向组件添加一个类,例如

import NextImage from 'next/image' //next component name it whatever
import styles from 'styles/mycss.module.css' //path to css file

<NextImage src="/url" className={styles.nextImageBackground} layout="fill"/>

//css file
.nextImageBackground{
    background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48cGF0aCBkPSJNMjI0IDM4Ny44MTRWNTEyTDMyIDMyMGwxOTItMTkydjEyNi45MTJDNDQ3LjM3NSAyNjAuMTUyIDQzNy43OTQgMTAzLjAxNiAzODAuOTMgMCA1MjEuMjg3IDE1MS43MDcgNDkxLjQ4IDM5NC43ODUgMjI0IDM4Ny44MTR6Ii8+PC9zdmc+')
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM