Is there a way to detect if the browser has subpixel precision?

后端 未结 4 392
失恋的感觉
失恋的感觉 2021-01-31 14:36

Is there a way to detect if the browser has subpixel precision for elements ?

IE9, unlike any of the other major browsers, has subpixel precision for its elements (an el

4条回答
  •  梦谈多话
    2021-01-31 15:18

    We had to do some serious pixel-perfect calculations recently, and I needed to check whether the browser was going to support subpixel layouts. I created a test for use in Conditionizr or Modernizr using some other answers as guides:

    conditionizr.add('subpixel-layout', function() {
        var $testWrap = $(
            '
    ' + '
    ' + '
    ' + '
    ' ).appendTo('body'); var supported = $('#subpixel-layout-1').position().top !== $('#subpixel-layout-2').position().top; $testWrap.remove(); return supported; });

    Then you can use with:

    conditionizr.on('!subpixel-layout', function () {
        // subpixel layout is NOT available
    });
    

    You should be able to do the same thing in Modernizr with Modernizr.addTest(), but I didn't test it.

    Obviously I'm using jQuery here, but should be pretty simple without it as well.

提交回复
热议问题