Open hongc-cc opened 6 years ago
You could also achieve this by using lazySizesConfig.rias.modifyOptions
(or the lazyriasmodifyoptions
event).
For example:
window.lazySizesConfig = {
rias: {
modifyOptions: function(data) {
var widths, maxWidth = data.target.dataset.maxWidth
if (maxWidth) {
widths = data.detail.widths.filter(function(width) {
return width <= maxWidth
})
data.detail.widths = widths.length ? widths : [+maxWidth]
}
},
},
}
Sometimes we know the original image dimension. we should be able to set
data-max-width
, so that service like imgix will not upscale image, or browser will not make new request due to new width parametere.g. A image with original width 400px,
data-src="https://foo.imgix.net/path/foo.jpg?w={width}"
will only transform todata-srcset="https://foo.imgix.net/path/foo.jpg?w=180 180w, https://foo.imgix.net/path/foo.jpg?w=320 320w, https://foo.imgix.net/path/foo.jpg?w=400 400w"