Raphael JS and Text positioning?

前端 未结 4 1468
花落未央
花落未央 2020-12-23 14:02

I\'m trying to position text within the SVG canvas, by supplying x, y coordinates

var t = paper.text(50, 50, \"Raphaël\\nkicks\\nbutt!\");
<         


        
4条回答
  •  难免孤独
    2020-12-23 14:28

    I know you didn't say you need to vertical align it to top, but if you want to use paper.text instead of paper.print... and would like to vertical align to be top.

    Try this:

    function alignTop(t) {
        var b = t.getBBox();
        var h = Math.abs(b.y2) - Math.abs(b.y) + 1;
    
        t.attr({
            'y': b.y + h
        });
    }
    

    And just pass the Raphael text object to it. It will top align it for you. and just call that function

提交回复
热议问题