What is an srcset attribute in IMG tag and how to use it?

前端 未结 3 712
误落风尘
误落风尘 2021-02-01 17:06

I want to know how could I start using the HTML srcset img attribute in my mobile apps. Or Is there any other jQuery plugin which helps me to solve image resolution

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 17:28

    Here is a good article on the srcset attribute and how to use it. srcet allows you to declare a set of images to be displayed on different viewport sizes. You just have to save and image at different resolutions e.g. banner-phone-HD.jpeg would be the highest resolution.

    Exmaple:

    my awesome image
    

    The above would serve banner-phone.jpeg to devices with viewport width under 640px, banner-phone-HD.jpeg to small screen high DPI devices, banner-HD.jpeg to high DPI devices with screens greater than 640px, and banner.jpeg to everything else.

    There are also other methods like CSS media queries you can use to produce the same effect.

    I am not aware of any JQuery plugins which would help with this.

提交回复
热议问题