-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting the current source size value of an img #6532
Comments
Would this be different from calling |
Yes; I want something that will return Then, I can compare that something to |
Spent a morning figuring out what I can do on my own: https://codepen.io/eeeps/pen/MWJyJKG?editors=1111. Not sure what I have is correct... (This would be a lot cleaner/easier with something like w3c/css-houdini-drafts#798) In any case, turning a source-size-value into an integer representing the resolved A couple of other thoughts:
|
This makes sense to me, and it seems easy for browsers to expose this information, and as demonstrated, relatively hard for web developers to get right. If you want to get it right including error handling or CSS syntax edge cases (e.g. |
Yeah, the use-case seems a little narrow, but reasonable, and the cost to expose it (pretty low) vs the cost to figure it out yourself (pretty high) seems to lean towards it being worthwhile to add. |
So... isn't this already exposed by |
@zcorpan Good point! When your Sometimes, though, no. Here are some tests of some edge cases I could think of: https://codepen.io/eeeps/pen/bGgqExq For linting purposes, I care a bit about the "incorrect w descriptor" case. When it comes to client hints (linting them, or polyfilling them), I care a lot about the "no srcset" case. I think all of the ❌s would be ✅s if we did #3981, though? |
@eeeps I like this I wonder if the code from the parse-sizes package (used in this "Sizes" extension for Firefox and Chrome) could help build something, while it's not native yet. |
If both Chrome and FF are using a package to provide something, that seems like a pretty strong vote for platform functionality |
I think sizes=auto (and its emerging complexities) makes this even more important. Developers are going to assume that sizes=auto is doing the right thing when if they're not careful, it won't. cc) @zcorpan I'm imagining a Lighthouse test or whatever that can check if sizes.currentSizes === img.clientWidth onload for imgs with sizes=auto. If not, there's been some hard-to-see problem. |
Sizes is hard and debugging it is hard.
Being able to automate debugging without implementing a
sizes
parser would be nice. I'd like to be able to compareimg.clientWidth
with something (img.currentSizes
?) that gave the current source size value inpx
. So, when:window.innerWidth = 1000
this
img
would have an
currentSizes
(or whatever) of800
.The text was updated successfully, but these errors were encountered: