Curtains with different image sources based on the viewport size
See original GitHub issueHey Martin,
Do you have any examples of CurtainsJS working with different image sources depending on the viewport size? It could or could not use the <picture>
element. I haven’t seen any material or demos on the subject. Looking at the texture docs I don’t see a straightforward way of doing this sort of thing but I very well could be missing something. Perhaps this sort of thing is what a texture loader could be used for? Any direction would be appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
curtains.js change texture source based on viewport size
... we'll cache the image\\n },\\n };\\n \\n // set the texture source dynamically based on viewport size\\n const setResponsiveTexture = () =>...
Read more >Responsive images - Learn web development | MDN
In this article, we'll learn about the concept of responsive images — images that work well on devices with widely differing screen sizes, ......
Read more >Load different images with HTML or CSS based on img size ...
It loads image based on viewport. In the question title it clearly says based on image size not screen size .
Read more >Responsive Images in Practice - A List Apart
The first problem we'll tackle: getting our images to scale efficiently across varying viewport widths and screen resolutions.
Read more >How to use Resolution Switching for Viewport based Image ...
The srcset attribute provides the browser with a set of image sources to choose from, including the size of each. It accepts a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my actual project I used data attributes to specify the image sources at different sizes and used a loop to keep the code more DRY:
Thanks again for the help!
My first answer may not have been clear, sorry about that. The thing is, you cannot upload a texture to the GPU if the image source itself is not already loaded (this is not a curtainsjs limitation, it’s just how WebGL works). That being said, this is up to you to load the right image and use it as your texture source whenever you want.
I’ve made this quick codepen to demonstrate how to achieve what I think you are trying to do: https://codepen.io/martinlaxenaire/pen/abmvyNG
Was this helpful?
Cheers,