简体   繁体   English

当我们单击下划线复选框时,如何在jcanvas jquery中的文本下划线

[英]how to underline the text in jcanvas jquery, when we click on underline checkbox

I'm creating a type of editor, where when a user enters the text in the textarea and clicks on add text, his/her text gets added to the canvas. 我正在创建一种类型的编辑器,当用户在文本区域中输入文本并单击添加文本时,他/她的文本将被添加到画布中。 So, I need an option that if the user would like to underline that particular text, he can do that as well.Here I have added checkbox for the Underline option. 因此,我需要一个选项,如果用户想在特定文本下划线,他也可以这样做。在这里,我为“下划线”选项添加了复选框。 I have done this using Jcanvas jquery. 我已经使用Jcanvas jquery做到了。

My html code is: 我的html代码是:

<input type="checkbox" id="Underline"  name="Underline" value="">Underline Add text<textarea id="add_text" ></textarea>   
<button onclick="addText()">add text</button>
<canvas id="maincanvas" width="500" height="400" style="background-color: #FFF;"> </canvas>

JavaScript code: JavaScript代码:

function addText(){
    var textvalue=document.getElementById("add_text");
    var $canvas = $("#maincanvas");

    $canvas.drawText({
      draggable: true,
      name: "demo",
      layer: true,
      fillStyle: "#000",
      x: 90,
      y: 10,
      text: textvalue,
    });
}

There are no 'text-decoration' or similar available in the text methods of the HTML Canvas Context. HTML Canvas Context的文本方法中没有“文本装饰”或类似内容。 You could make it bold or oblique( via the fontStyle property) but underline is not available. 您可以将其设置为粗体或斜体(通过fontStyle属性),但是下划线不可用。

But they exist a workaround, explained here . 但是它们存在解决方法, 在此进行说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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