Detect scale settings (dpi) with JavaScript or CSS

后端 未结 3 508
一生所求
一生所求 2021-02-08 02:27

I\'ve noticed that a small laptop with a 1920x1080 screen, windows 10 will auto adjust the scaling. I\'ve seen it as high as 150%. Is there a way we can detect this? My media qu

3条回答
  •  灰色年华
    2021-02-08 03:15

    For anyone looking into this, building a little on Martin Adamek's answer, you can do this in jQuery and scale something with CSS transform:

    // if the user has display scaling active, scale with CSS transform    
    if (window.devicePixelRatio !== 1){
        let scaleValue = (1/window.devicePixelRatio);
        $('#containerToBeScaled').css('transform','scale('+scaleValue+')');
    }
    

    This works well if you have a pop-Up for example and you want it to look the same regardless of display scaling

提交回复
热议问题