【问题标题】:Fabric.js align right and underline not working togetherFabric.js 右对齐和下划线不一起工作
【发布时间】:2013-11-13 18:17:04
【问题描述】:

我有 2 个按钮首先将文本对齐到“右”,第二个按钮是设置下划线。

第一个问题:: 但是,如果文本向右对齐并且我单击下划线按钮,我会得到如下所示的内容,

第二个问题:: 如果文本向右或向左对齐[创建了另一个按钮],那么对于这两个按钮文本仅向右移动,我创建的文本错误??

添加文字的方法是:

hw[i] = new fabric.Text($(this).val(), {
            left : drawleft,
            top : drawtop,
            fontSize : 20,
            textAlign: 'center'
        });

jquery 代码是 ::

    $('#font_un').click(function(event) {
        event.stopPropagation();
         ++index;
   action=true;  

        var obj = canvas.getActiveObject();

        if (!obj)
            return;

        if (un_flag == 0) {

            obj.set('textDecoration', 'underline');
            un_flag = 1;
        } else {
            obj.set('textDecoration', '');
            un_flag = 0;
        }

        canvas.renderAll();

    });

$(document).on("click","#font-right",function(event){

        var obj = canvas.getActiveObject();
         ++index;
   action=true;  

        event.stopPropagation();
        if (!obj)
            return;

        obj.set('textAlign', 'right');

        canvas.renderAll();
    });

【问题讨论】:

    标签: html canvas fabricjs


    【解决方案1】:

    解决了我的问题,我应该使用错误的方法

    obj.set('originX', 'center').setCoords();
    
            canvas.renderAll();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      相关资源
      最近更新 更多