因此,根据 this article ,您可以使用以下方法对 Canvas 混合模式进行功能测试:
Modernizr.addTest('canvasblending', function () {
if (Modernizr.canvas === false) return false;
var ctx = document.createElement('canvas').getContext('2d');
ctx.globalCompositeOperation = 'screen';
return ctx.globalCompositeOperation == 'screen';
});
在 Chrome 27 中返回误报。
最佳答案
我写了一些有用的东西,但它非常丑陋,但我认为它可以帮助其他人或者我们可以得到更好的东西。这是我想出的:
Modernizr.addTest('canvasblending', function() {
if ( ! Modernizr.canvas ) return false;
var canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
var ctx = canvas.getContext('2d');
ctx.fillStyle = '#000';
ctx.fillRect(0,0,1,1);
ctx.globalCompositeOperation = 'multiply';
ctx.fillStyle = '#fff';
ctx.fillRect(0,0,1,1);
return ctx.getImageData(0,0,1,1).data[0] === 0;
});
关于javascript - 如何使用 globalCompositeOperation 测试 Canvas 混合模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17553357/