Replies: 10 comments 9 replies
-
My understanding is that the To show different images based on different screen widths, the preferred solution seems to be use of the <picture>
<source srcset="/media/cc0-images/surfer-240-200.jpg"
media="(min-width: 800px)">
<img src="/media/cc0-images/painted-hand-298-332.jpg" alt="" />
</picture>
|
Beta Was this translation helpful? Give feedback.
-
That is precisely why I opened this issue, I think that the |
Beta Was this translation helpful? Give feedback.
-
+1 for this, I have been trying a lot but still couldn't get Next Image works similar to |
Beta Was this translation helpful? Give feedback.
-
You could use a custom loader for this: https://nextjs.org/docs/api-reference/next/image#loader Based on the width, you could show a different image. |
Beta Was this translation helpful? Give feedback.
-
I think it could be done programmatically (I have not done tests), but, why not be able to use the same feature of the Image component to achieve it in the classic way that HTML5 already provides us? I think that many developers would like to work more semantically than programmatically. As I mentioned in the issue, this feature is widely used in e-commerce sites where an image must be represented according to the width of the graphic window. |
Beta Was this translation helpful? Give feedback.
-
there's also this RFC: #25393 |
Beta Was this translation helpful? Give feedback.
-
this is done https://nextjs.org/docs/pages/api-reference/components/image#art-direction |
Beta Was this translation helpful? Give feedback.
-
I am late to the party, but how about you create two separate image components and solve it with css display: none? I know it's a bit verbose, and it is indeed a bit more expensive to have two components. however, this is clearly free from layout shifts and prevents you from downloading two images for each break points, and bonus point for using nextjs/image!
|
Beta Was this translation helpful? Give feedback.
-
The <Image
src={batteryPicture}
alt="Background image of battery installed on home."
sizes="(min-width: 768px) 100vh, 0px"
priority
/> I also edited my const nextConfig: NextConfig = {
images: {
// we add the `1` width so that we can send the smallest possible image to views where an image is hidden and `priority`.
imageSizes: [1, 16, 32, 48, 64, 96, 128, 256, 384],
},
}; |
Beta Was this translation helpful? Give feedback.
-
Hi. Any ideas for implementing this is on older versions of Next (v13)? I don't want to update the Next version using just because of this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What version of Next.js are you using?
10.2.0
What version of Node.js are you using?
12.18.3
What browser are you using?
Chrome
What operating system are you using?
Windows
How are you deploying your application?
localhost
Describe the Bug
By using the
next/image
component I need it to be able to decide which image to display depending on the device window. For example, if I am on a smartphone I want a superhero image to be shown while if I am in a desktop size I want a car image to be displayed.This is possible using
img
using thesrcset
andsizes
attributes but using thenext/image
component this does not work.Expected Behavior
The behavior I expect is to be able to display an "A" image on small screens while on larger screens to display a "B" image.
Similar to using
picture
withsource
or usingimg
withsrcsets
andsizes
.To Reproduce
Use the component
Image
as followsBeta Was this translation helpful? Give feedback.
All reactions