<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 事件的矩形

        Create a rectangle with mousedown event in KineticJS(在 KineticJS 中创建一个带有 mousedown 事件的矩形)

          <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 事件的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)

                  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>
                          <tbody id='MdaSe'></tbody>

                        <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>