【问题标题】:Kineticjs: fillAlpha() has no effect?Kineticjs:fillAlpha() 没有效果?
【发布时间】:2014-04-19 20:54:18
【问题描述】:

我尝试使用 Kineticjs 形状的 fillAlpha() 函数,但它不会改变填充颜色的 alpha。

这就是我所做的:

var stage = new Kinetic.Stage({
        container: 'container',
        width: 578,
        height: 200
      });

      var layer = new Kinetic.Layer();

      var circle = new Kinetic.Circle({
        x: stage.getWidth() / 2,
        y: stage.getHeight() / 2,
        radius: 70,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 4
      });

       circle.fillAlpha(0.5);

      // add the shape to the layer
      layer.add(circle);

      // add the layer to the stage
      stage.add(layer);

circle.fillAlpha(0.5);对填充没有影响。

这是一个用于演示的 JsFiddle:http://jsfiddle.net/VKNLM/

如何更改填充颜色的 alpha?

【问题讨论】:

    标签: javascript html canvas kineticjs


    【解决方案1】:

    您必须使用fillfillRedfillBluefillGreenfillAlpha 分开。不要一起使用。

    所以你可以这样做:

    circle.opacity(0.5);
    

    var circle = new Kinetic.Circle({
        x: stage.getWidth() / 2,
        y: stage.getHeight() / 2,
        radius: 70,
        fillRed: 255,
        stroke: 'black',
        strokeWidth: 4
      });
    circle.fillAlpha(0.5)
    

    【讨论】:

    • 这是正确的,您不能将fill 与fillAlpha 一起使用,您必须使用单独的通道。 @confile,您的问题的另一种解决方案可能是使用填充:'rgba(255,0,0,0.5)',使其变为红色并半透明。
    猜你喜欢
    • 2012-10-30
    • 2018-05-21
    • 2018-07-28
    • 2018-05-15
    • 1970-01-01
    • 2011-10-01
    • 2015-05-31
    • 2020-10-19
    • 1970-01-01
    相关资源
    最近更新 更多