fabric.js to show mirror image of canvas text

淺唱寂寞╮ 提交于 2020-01-02 12:01:41

问题


i am using fabric.js to write text on canva .later on click of button i want to show mirror image of text . is there any property in fabric.js which i can use to rotate text on canvas.

Please check , http://jsfiddle.net/BTh6A/9/

document.getElementById( 'btn' ).addEventListener( 'click', function (e) {
    var obj = canvas.getActiveObject();

    if ( !obj ) return;

    //here comes code to show mirror image

    obj.set( 'fill', '#FF0000' );
    canvas.renderAll();
});

回答1:


Try this piece of code...I have edited it..

document.getElementById('btn').addEventListener('click', function (e) {

    canvas.getActiveObject().set("angle", "-180").set('flipY', true);
    canvas.renderAll();

});



回答2:


function flipX() {
    var obj = canvas.getActiveObject();
    if (obj) {
        obj.set('flipX', !obj.flipX);
        canvas.renderAll();
    }
}

function flipY() {
    var obj = canvas.getActiveObject();
    if (obj) {
        obj.set('flipY', !obj.flipY);
        canvas.renderAll();
    }
}


来源:https://stackoverflow.com/questions/18482997/fabric-js-to-show-mirror-image-of-canvas-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!