简体   繁体   中英

How to set font-size dynamically in JointJs?

I am developing a JointJs Application,I need to set font-size for a text inside a rectangle.

    $('#FText,#FTextHeight,#FTextWidth,#FTextSize').on('keyup change', function () {
    var FtHeight = $('#FTextHeight').val();
    var FtWidth = $('#FTextWidth').val();
    var FtSize = parseInt($('#FTextSize').val());
    var txt = $('#FText').val();
    graph2.clear();
    if (txt.length > 0) {
        $('#FTexterror').empty();
        var myFtext = new joint.shapes.basic.Rect({
            position: { x: 50, y: 50 },
            size: { width: FtWidth, height: FtHeight },
            attrs: {
                rect: {
                    fill: 'white', stroke: outerColor, 'class': 'customtext',
                },
                text: {
                    text: txt, 'letter-spacing': 1, 'font-size': FtSize,
                    fill: outerColor, 'font-size': 11, 'y-alignment': 'middle',
                }
            }
        });
        graph2.addCells([myFtext]);
    }
    else {
        $('#FTexterror').empty().append('*Enter valid text');
    }
});

the above code is not working while setting font-size for the text. Kindly help me on this

try this

$('.input-text')
    .val(rect.attr('text/font-size')) //set initial value
    .on('keyup', function () {

        var val = $(this).val();
        rect.attr('text/font-size', val);
});

complete demo: https://jsfiddle.net/vtalas/sav49mj4/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM