Pixel to MM equation?

后端 未结 9 900
心在旅途
心在旅途 2020-12-01 16:44

Is there a reliable equation to work out pixel size to MM? Or is that not possible cross device?

We are working with a bespoke system that delivers content to many

9条回答
  •  甜味超标
    2020-12-01 17:04

    Based on the @Dawa answer above, this is my solution:

    var mmToPx = function(mm) {
        var div = document.createElement('div');
        div.style.display = 'block';
        div.style.height = '100mm';
        document.body.appendChild(div);
        var convert = div.offsetHeight * mm / 100;
        div.parentNode.removeChild(div);
        return convert;
    };
    

    Just note that the 100mm height, will give you a better precision factor. The calculation will be instant and the div will not be visible. No need for jQuery

提交回复
热议问题