<small id='nHjwU'></small><noframes id='nHjwU'>

        <bdo id='nHjwU'></bdo><ul id='nHjwU'></ul>

    1. <legend id='nHjwU'><style id='nHjwU'><dir id='nHjwU'><q id='nHjwU'></q></dir></style></legend>
    2. <tfoot id='nHjwU'></tfoot>

      1. <i id='nHjwU'><tr id='nHjwU'><dt id='nHjwU'><q id='nHjwU'><span id='nHjwU'><b id='nHjwU'><form id='nHjwU'><ins id='nHjwU'></ins><ul id='nHjwU'></ul><sub id='nHjwU'></sub></form><legend id='nHjwU'></legend><bdo id='nHjwU'><pre id='nHjwU'><center id='nHjwU'></center></pre></bdo></b><th id='nHjwU'></th></span></q></dt></tr></i><div id='nHjwU'><tfoot id='nHjwU'></tfoot><dl id='nHjwU'><fieldset id='nHjwU'></fieldset></dl></div>

        在 KineticJS 中创建一个带有 mousedown 事件的矩形

        时间:2023-06-20

          <tbody id='xQvvg'></tbody>

            • <bdo id='xQvvg'></bdo><ul id='xQvvg'></ul>
              <tfoot id='xQvvg'></tfoot>
            • <i id='xQvvg'><tr id='xQvvg'><dt id='xQvvg'><q id='xQvvg'><span id='xQvvg'><b id='xQvvg'><form id='xQvvg'><ins id='xQvvg'></ins><ul id='xQvvg'></ul><sub id='xQvvg'></sub></form><legend id='xQvvg'></legend><bdo id='xQvvg'><pre id='xQvvg'><center id='xQvvg'></center></pre></bdo></b><th id='xQvvg'></th></span></q></dt></tr></i><div id='xQvvg'><tfoot id='xQvvg'></tfoot><dl id='xQvvg'><fieldset id='xQvvg'></fieldset></dl></div>

                <legend id='xQvvg'><style id='xQvvg'><dir id='xQvvg'><q id='xQvvg'></q></dir></style></legend>

                  <small id='xQvvg'></small><noframes id='xQvvg'>

                  本文介绍了在 KineticJS 中创建一个带有 mousedown 事件的矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用带有 mousedown 和拖动事件的 KineticJS 创建一个矩形形状,但运气不佳.有没有人做过类似的事情?

                  I am trying to create a rectangle shape using KineticJS with mousedown and drag events but not having much luck with it. Has anyone done anything similar?

                  推荐答案

                  http://jsfiddle.net/AYHSM/6/

                  var stage = new Kinetic.Stage({
                      container: 'container',
                      width: 600,
                      height: 400
                  });
                  
                  var layer = new Kinetic.Layer();
                  layer.add(new Kinetic.Rect({
                      x:0,
                      y:0,
                      width:600,
                      height:400
                  }));  // this rect will allow us to use mouse events on the layer. There's probably a better way to do this, but I don't know it.
                  stage.add(layer);
                  var rect, down = false; // down is a flag to know whether or not the mouse button is down so that we only resize the new rect when it is down.
                  
                  layer.on("mousedown", function(e) {
                  
                      down = true;
                      var r = Math.round(Math.random()*255),
                          g = Math.round(Math.random()*255),
                          b = Math.round(Math.random()*255);
                      rect = new Kinetic.Rect({
                          x: e.layerX,
                          y: e.layerY,
                          width: 11,
                          height: 1,
                          fill: 'rgb('+r+','+g+','+b+')',
                          stroke: 'black',
                          strokeWidth: 4
                      });
                      layer.add(rect);
                  });
                  
                  layer.on("mousemove", function(e) {
                      if (!down) return;
                  
                      var p = rect.attrs;
                  
                      rect.setWidth(e.layerX - p.x);
                      rect.setHeight(e.layerY - p.y);
                      layer.draw();
                  });
                  
                  layer.on("mouseup", function(e) {
                      down = false;
                  });
                  

                  这篇关于在 KineticJS 中创建一个带有 mousedown 事件的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Html 5 canvas getElementById() 返回 null/undefined 下一篇:调整浏览器大小后如何获取画布的宽度和高度

                  相关文章

                  1. <i id='MdaSe'><tr id='MdaSe'><dt id='MdaSe'><q id='MdaSe'><span id='MdaSe'><b id='MdaSe'><form id='MdaSe'><ins id='MdaSe'></ins><ul id='MdaSe'></ul><sub id='MdaSe'></sub></form><legend id='MdaSe'></legend><bdo id='MdaSe'><pre id='MdaSe'><center id='MdaSe'></center></pre></bdo></b><th id='MdaSe'></th></span></q></dt></tr></i><div id='MdaSe'><tfoot id='MdaSe'></tfoot><dl id='MdaSe'><fieldset id='MdaSe'></fieldset></dl></div>
                    <tfoot id='MdaSe'></tfoot>
                    1. <small id='MdaSe'></small><noframes id='MdaSe'>

                      <legend id='MdaSe'><style id='MdaSe'><dir id='MdaSe'><q id='MdaSe'></q></dir></style></legend>
                        <bdo id='MdaSe'></bdo><ul id='MdaSe'></ul>