【问题标题】:How to check if HTML5 Canvas blend modes are supported in my browser?如何检查我的浏览器是否支持 HTML5 Canvas 混合模式?
【发布时间】:2015-12-21 11:34:25
【问题描述】:

如何以编程方式查找我的浏览器是否支持 HTML5 混合模式 (http://www.w3.org/TR/compositing-1/#mix-blend-mode)?

我的代码结构如下

    var canvas = document.getElementById("Canvas");
    var context = canvas.getContext("2d");

    context.fillStyle = "#fff";
    context.fillRect(0, 0, canvas.width, canvas.height);

    context.globalCompositeOperation = "source-over"
    context.globalCompositeOperation = "soft-light";
    if (context.globalCompositeOperation){
      //browser supports
      alert('true');
    }
    else {
      // browser doesn't support
      alert('false');
    }

但它似乎无法正常工作。即使在 IE 中它也会提醒“真实”。 (http://caniuse.com/#search=blend 表示 IE 不支持混合模式)

【问题讨论】:

标签: javascript html canvas


【解决方案1】:

你应该使用

context.globalCompositeOperation = blendMode;
if (context.globalCompositeOperation !== blendMode){
     // not supported mode
}

【讨论】:

  • 这在大多数情况下都可以使用,除了在 Safari 中,一些混合模式(“色调”、“饱和度”、“颜色”、“亮度”)将被接受但实际上并不支持。 In this answer 你可以找到一种方法来真正测试每个 globalCompositeOperation 模式。
猜你喜欢
  • 2020-01-04
  • 1970-01-01
  • 2011-02-10
  • 2010-11-29
  • 1970-01-01
  • 1970-01-01
  • 2021-12-25
  • 1970-01-01
相关资源
最近更新 更多