Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript resize rect一旦我在其中添加了test,dynamicy.js,它就不起作用了_Javascript_Jquery_Html5 Canvas_Kineticjs - Fatal编程技术网

Javascript resize rect一旦我在其中添加了test,dynamicy.js,它就不起作用了

Javascript resize rect一旦我在其中添加了test,dynamicy.js,它就不起作用了,javascript,jquery,html5-canvas,kineticjs,Javascript,Jquery,Html5 Canvas,Kineticjs,我有代码可以在dynamic.js中调整rect的大小,它只工作一次。在这之后,它不会使rect的大小调整,在这里我试图在rect内添加文本,但一旦我在rect内设置文本,点击“框”上的事件,不会在第二次触发,请建议 var box = new Kinetic.Rect({ x : relativeX,

我有代码可以在dynamic.js中调整rect的大小,它只工作一次。在这之后,它不会使rect的大小调整,在这里我试图在rect内添加文本,但一旦我在rect内设置文本,点击“框”上的事件,不会在第二次触发,请建议

                                var box = new Kinetic.Rect({                             
                                    x : relativeX,
                                    y : relativeY,
                                    offset : [ 50, 25 ],
                                    width : 100,
                                    height : 50,
                                    fill : 'yellow',
                                    stroke : 'black',
                                    strokeWidth : 1,                             
                                    id:'comment'  
                                });    
                                group.add(box);     
                                 var simpleText = new Kinetic.Text({
                                        x : relativeX - 48,
                                        y : relativeY - 30,                      
                                        text : 'Note',
                                        fontSize : 15,
                                        fontFamily : 'Calibri',
                                        width:box.getWidth(),
                                        height:box.getHeight(),
                                        padding: 4,
                                        fill : 'green',
                                        id:"textBox"    
                                });
                                 group.add(simpleText); 
                                var circle1 = new Kinetic.Circle({    
                                    x: relativeX+50,
                                    y:relativeY+25,    
                                    radius: 4,
                                    fill: 'red',
                                    stroke: 'black',
                                    strokeWidth: 1,                        
                                    draggable: true,
                                    visible:false
                                });

                                group.add(circle1);                                                          
                                layer.draw();    
                                circle1.on("dragmove",function()                         
                                        var pos = this.getPosition();
                                        var x = pos.x;
                                        var y = pos.y;
                                        var rectX = box.getX();
                                        var rectY = box.getY();
                                        var x1= x - rectX;
                                        var y1= y - rectY;                                                                  
                                        box.setSize(x1+50,y1+25); 

                                        var textX=simpleText.getX();
                                        var textY=simpleText.getY();
                                        var x2= x - textX;
                                        var y2= y - textY;      
                                        simpleText.setSize(x2,y2); 

                                        var circle1X=circle1.getX();
                                        var circle1Y=circle1.getY();
                                        var x3=x-circle1X;
                                        var y3=y-circle1Y;
                                        circle1.setSize(x3,y3); 
                                        layer.draw();    
                                    }); 

                                box.on('mouseover', function() {
                                document.body.style.cursor = 'pointer';  });

                                box.on('mouseout', function() {
                                document.body.style.cursor = 'default';  });

                                circle1.on('mouseover', function() {
                                document.body.style.cursor = 'se-resize'; });

                                circle1.on('mouseout', function() {
                                document.body.style.cursor = 'default';  });


                                  group.on('click', function(evt) {     
                                      var shape =circle1.getVisible();                                          
                                      if( shape==false)
                                             {                                  
                                              circle1.show();
                                              layer.draw();   
                                              $('html').on('keydown',function(e){     
                                                   if(e.keyCode === 46){                             
                                                        group.destroy();
                                                        layer.draw();                                                
                                                    } 
                                             });    
                                             }else{
                                                circle1.hide();
                                                layer.draw();
                                               }    
                                      circle1.setVisible(false);  
                               }); 

         var canvas = document.getElementById('canDemo');   
                                 var canvas = document.getElementById('canDemo');
                                  ctx = canvas.getContext('2d'),
                                  font = '14px sans-serif',
                                  hasInput = false;   

                                  box.on('dblclick', function() {       
                                     // canvas.onclick = function(e) {                   
                                          if (hasInput) return;
                                          addInput(e.clientX, e.clientY);             
                                        });    

                              function addInput(x, y) {                       
                                  var input = document.createElement('textarea');       
                                  input.id="comment_area";
                                  input.type = 'textarea';
                                  input.style.position = "absolute";    
                                  input.style.left = (x - 4) + 'px';
                                  input.style.top = (y - 4) + 'px';
                                  input.style.zIndex="3"; 
                                  input.onkeydown = handleEnter;                            
                                  document.body.appendChild(input);
                                  input.focus();                          
                                  hasInput = true;  } 

                              function handleEnter(e) {
                                  var keyCode = e.keyCode;
                                  if (keyCode === 27) {                                    

                                  simpleText.setText( $("#comment_area").val());    
                                  drawText(this.value, parseInt(this.style.left, 10), parseInt(this.style.top, 10));    
                                      document.body.removeChild(this);
                                      hasInput = false;
                                  }   
                              }                         

                              $('#comment_area').keypress(function (e){
                                    if(e.keyCode === 13){
                                        e.preventDefault();
                                        this.value = this.value.substring(0, this.selectionStart)+"\n";
                                    }    
                                });

                              function drawText(txt, x, y) {
                                  ctx.textBaseline = 'top';
                                  ctx.textAlign = 'left';
                                  ctx.font = font;
                                  ctx.fillText(txt, x - 4, y - 4);
                                  layer.draw();}

请为itAnybody创建fiddle是否知道如何在函数之外获取返回值?类似于var c myRect.on(“click”,function(){c=a+b});警报(“添加为:+c”);这里考虑myRect是在画布上绘制的矩形。意味着我想在代码中获取返回值true或false,这样我就可以在函数外编写条件,比如if(true)。。