最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to set a textbox text dynamically in fabric js Itext - Stack Overflow

programmeradmin2浏览0评论

i create a canvas, i add a fabric Itext, i want to fill text of textbox in Itext. my html code is...

 <input type="text" id="title" placeholder="Your Title" /><br>
<canvas id="c"></canvas>

and javascript...

function Addtext() { 
var text = new fabric.IText('Enter text here...',      {fontSize:16,left:20,top:20,radius:10});
borderRadius = "25px";
canvas.add(text).setActiveObject(text);
text.hasRotatingPoint = true;
}

document.getElementById('title').addEventListener('keyup', function () {
var stringTitle = document.getElementById('title').value;
});

please help...thanks in advance.

i create a canvas, i add a fabric Itext, i want to fill text of textbox in Itext. my html code is...

 <input type="text" id="title" placeholder="Your Title" /><br>
<canvas id="c"></canvas>

and javascript...

function Addtext() { 
var text = new fabric.IText('Enter text here...',      {fontSize:16,left:20,top:20,radius:10});
borderRadius = "25px";
canvas.add(text).setActiveObject(text);
text.hasRotatingPoint = true;
}

document.getElementById('title').addEventListener('keyup', function () {
var stringTitle = document.getElementById('title').value;
});

please help...thanks in advance.

Share Improve this question asked Sep 30, 2016 at 13:49 Kishor AdmaneKishor Admane 691 silver badge11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Your question is very vague. this seems to be something close to what you are asking for. As you type in the textbox the iText updates. Although you can just click in to the iText on the canvas and type right in to so I'm not sure if you really need the html input at all.

window.canvas = new fabric.Canvas('c');

var textOptions = { 
  fontSize:16, 
  left:20, 
  top:20, 
  radius:10, 
  borderRadius: '25px', 
  hasRotatingPoint: true 
};

var textObject = new fabric.IText('Enter text here...', textOptions);

canvas.add(textObject).setActiveObject(textObject);
canvas.renderAll()

document.getElementById('title').addEventListener('keyup', function () {
  textObject.text = document.getElementById('title').value;
  canvas.renderAll();
});
canvas { border: 1px solid; }
<script src="https://cdnjs.cloudflare./ajax/libs/fabric.js/1.6.4/fabric.min.js" ></script>
<input type="text" id="title" placeholder="Your Title" /><br>
<canvas id="c"></canvas>

发布评论

评论列表(0)

  1. 暂无评论