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
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.