<tfoot id='2wEIR'></tfoot>

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

    1. <small id='2wEIR'></small><noframes id='2wEIR'>

    2. <legend id='2wEIR'><style id='2wEIR'><dir id='2wEIR'><q id='2wEIR'></q></dir></style></legend>

      Fabric.js 动态裁剪单个对象

      Fabric.js clipping individual objects dynamically(Fabric.js 动态裁剪单个对象)

      <small id='5hN1L'></small><noframes id='5hN1L'>

        <legend id='5hN1L'><style id='5hN1L'><dir id='5hN1L'><q id='5hN1L'></q></dir></style></legend>

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

                <bdo id='5hN1L'></bdo><ul id='5hN1L'></ul>
                本文介绍了Fabric.js 动态裁剪单个对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在动态添加一个矩形元素来裁剪/剪辑(使用clipTo)选定的元素,它在第一次时效果很好,但是当我在画布上添加第二个元素并开始裁剪第二个元素时,第一个元素会丢失裁剪/剪辑.下面是我的代码,有 2 个按钮 1 开始裁剪/剪辑(在要裁剪的元素上放置一个动态矩形)第二个进行裁剪/剪辑.

                I am dynamically adding a rect element to crop/clip (using clipTo) a selected element, It works perfect at the first time but when i add a second element to the canvas and begin to crop the second element the first element looses the crop/clip. Below is my code, there are 2 buttons 1 to start crop/clip (places a dynamic rect over the element to be cropped) second to do the cropping/clipping.

                $('#crop').on('click', function (event) {
                
                
                    var left = el.left - object.left;
                    var top = el.top - object.top;
                
                    left *= 1;
                    top *= 1;
                
                    var width = el.width * 1;
                    var height = el.height * 1;
                
                  object.clipTo = function (ctx) 
                  {
                        ctx.rect(-(el.width/2)+left, -(el.height/2)+top, parseInt(width*el.scaleX), parseInt(el.scaleY*height));
                  }
                
                
                
                    for(var i=0; i<$("#layers li").size();i++)
                        {
                            canvas.item(i).selectable= true;
                        }
                    disabled = true;
                
                    canvas.remove(canvas.getActiveObject());
                    lastActive = object;
                    canvas.renderAll();
                
                
                
                });
                
                $('#startCrop').on('click',function(){
                
                    canvas.remove(el);
                    if(canvas.getActiveObject())
                    {
                
                    object=canvas.getActiveObject();    
                    if (lastActive && lastActive !== object) {
                        lastActive.clipTo = null;
                    }
                
                
                
                        el = new fabric.Rect
                        ({
                            fill: 'rgba(0,0,0,0.3)',
                            originX: 'left',
                            originY: 'top',
                            stroke: '#ccc',
                            strokeDashArray: [2, 2],
                            opacity: 1,
                            width: 1,
                            height: 1,
                            borderColor: '#36fd00',
                            cornerColor: 'green',
                            hasRotatingPoint:false
                        });
                
                        el.left=canvas.getActiveObject().left;
                        selection_object_left=canvas.getActiveObject().left;
                        selection_object_top=canvas.getActiveObject().top;
                        el.top=canvas.getActiveObject().top;
                        el.width=canvas.getActiveObject().width*canvas.getActiveObject().scaleX;
                        el.height=canvas.getActiveObject().height*canvas.getActiveObject().scaleY;
                
                
                        canvas.add(el);
                        canvas.setActiveObject(el);
                        for(var i=0; i<$("#layers li").size();i++)
                            {
                                canvas.item(i).selectable= false;
                            }
                    }
                
                    else{
                            alert("Please select an object or layer");
                        }
                
                });
                

                推荐答案

                这就是你要找的吗?http://jsfiddle.net/86bTc/4/

                你设置lastActive.clipTo = null;

                这篇关于Fabric.js 动态裁剪单个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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(我想沿特定路径对对象进行动画处理)
                How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                • <bdo id='29Dfz'></bdo><ul id='29Dfz'></ul>
                  <legend id='29Dfz'><style id='29Dfz'><dir id='29Dfz'><q id='29Dfz'></q></dir></style></legend>

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

                            <tbody id='29Dfz'></tbody>