Serving high res images to retina display

后端 未结 3 1868
旧时难觅i
旧时难觅i 2020-12-08 03:32

how to detect, in a cross-browser compatible way, the pixel density of the device visiting a webpage so that one can either serve standard or highres images

3条回答
  •  执笔经年
    2020-12-08 04:05

    I found this:

    var retina = window.devicePixelRatio > 1;
    

    this should make retina return true, which you could use an if function to serve the right images.

    Source: http://briancray.com/posts/detect-retina-displays-with-javascript

    -InfiniDaZa

提交回复
热议问题