在画布上移动两条以上的箭头线

moving more than two arrow lines on canvas

本文关键字:两条 移动      更新时间:2023-09-26

这是我使用动力学的代码.js我画三条线并使用鼠标移动。

$(document).ready(function(){   
 var y1=50;
 var stage = new Kinetic.Stage({
          container: "container",
          width: 578,
          height: 200
    });
 var layer = new Kinetic.Layer();
 var group=new Kinetic.Group({
          draggable: true,
          dragConstraint : 'horizontal'
    });

var lineme =function(pts){
var line1 = new Kinetic.Line({
      points: pts,
      stroke: "black",
      strokeWidth: 4,
      lineCap: 'round',
      lineJoin: 'round',
    });
    group.add(line1);
   }
 for(a=0;a<=2;a++)
 {
     var points1 = [{
          x: 73,
          y: y1
        }, {
          x: 300,
          y: y1
        }];
      lineme(points1);
      y1=y1+50;
  }
   group.on("mouseover", function(){
          document.body.style.cursor = "pointer";
        });
   group.on("mouseout", function() {
      document.body.style.cursor = "default";
    });
    // add the shape to the layer       
    layer.add(group);
    // add the layer to the stage
    stage.add(layer);
 });

我想画箭头线,我尝试了更多时间,但我找不到正确的解决方案。他们在动态js中的任何箭头函数都可以帮助我吗

您必须创建一个组并将两行添加到该组中。

检查以下示例:http://www.html5canvastutorials.com/kineticjs/html5-canvas-drag-and-drop-a-group-with-kineticjs/

希望对您有所帮助!

var line2 = .....
// add another line to the layer before adding it to the stage
layer.add(line2);

肯定?