开发者

Applying attribute to SVG using JS prompts 'this.textBox.style is undefined'. Why?

开发者 https://www.devze.com 2023-01-03 13:22 出处:网络
I\'m using the following code to draw an SVG text box, and then cha开发者_如何学Gonge its text anchor attribute to \'left\' as it defaults to center and that\'s nasty.

I'm using the following code to draw an SVG text box, and then cha开发者_如何学Gonge its text anchor attribute to 'left' as it defaults to center and that's nasty.

The text generates correctly, but when I add this second line I get the error 'this.textBox.style is undefined' in my error console.

Here's my code:

    RenderTextBox:function()
{
    // Render Text
    this.textBox = paper.text(this.x, this.y, this.htmlText);
    this.textBox.style.textAnchor="left";
}

Any ideas?


I think what you want to do is

this.textBox.setAttribute('text-anchor', 'start');

(or, since it looks like you're using Raphael)

this.textBox.attr( 'text-anchor', 'start' );

The valid values for text-anchor are start, middle, end, and inherit


You can set it using bracket notation:

    this.textBox.style['text-anchor'] = "left";

This way you don't actually have to make a function call.

0

精彩评论

暂无评论...
验证码 换一张
取 消