【问题标题】:Dashed Arrow Head Filled With Color充满颜色的虚线箭头
【发布时间】:2021-06-15 12:40:00
【问题描述】:

我使用 konvajs 使用虚线创建 Konva.Arrow 形状。但是,箭头没有填充颜色。如何让箭头有颜色?

这是我用来制作箭头的代码的基础。

lineConfig['dash'] = [12, 8];
lineConfig['points'] = [pos.x, pos.y];
arrowLine = new Konva.Arrow(lineConfig);

【问题讨论】:

    标签: javascript html5-canvas konvajs


    【解决方案1】:

    尝试将fill 属性也添加到您的箭头中,例如fill: 'black'。我试图在没有该属性的情况下绘制箭头,得到的结果与您描述的相同。

    以下是工作示例:

    <!DOCTYPE html>
    <html>
      <head>
        <script src="https://unpkg.com/konva@7.2.5/konva.min.js"></script>
        <meta charset="utf-8" />
        <title>Konva Arrow Demo</title>
        <style>
          body {
            margin: 0;
            padding: 0;
            overflow: hidden;
            background-color: #f0f0f0;
          }
        </style>
      </head>
      <body>
        <div id="container"></div>
        <script>
          var width = window.innerWidth;
          var height = window.innerHeight;
    
          var stage = new Konva.Stage({
            container: "container",
            width: width,
            height: height
          });
    
          var layer = new Konva.Layer();
    
          var arrow = new Konva.Arrow({
            x: stage.width() / 4,
            y: stage.height() / 4,
            points: [0, 0, 10, 100],
            pointerLength: 20,
            dash: [12, 8],
            pointerWidth: 20,
            // Comment the following line to get your issue
            fill: "black",
            stroke: "black",
            strokeWidth: 4
          });
    
          // add the shape to the layer
          layer.add(arrow);
    
          // add the layer to the stage
          stage.add(layer);
        </script>
      </body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 2015-03-07
      • 2013-08-04
      • 1970-01-01
      • 2017-02-22
      相关资源
      最近更新 更多