html5 - How to activate the cursor for a fabric js IText? -
i'd able add text canvas , have go directly editing text mode cursor visible , can start typing.
so far i've got code adds text , sets active, i'm not sure on how go edit text mode. ideas? thanks!
var fabictext = new fabric.itext('click change text', { left: 100, top: 100 }); fabictext.set({ fill: getselectedcolortext() }); _fabiccanvas.add(fabictext); _fabiccanvas.setactiveobject(fabictext);
you have use enterediting()
method , set focus on hiddentextarea this
fabictext.enterediting(); fabictext.hiddentextarea.focus();
var _fabiccanvas; $(function () { _fabiccanvas = window._canvas = new fabric.canvas('canvas'); var fabictext = new fabric.itext('click change text', { left: 100, top: 100 }); _fabiccanvas.add(fabictext); fabictext.set({ fill: 'blue' }); _fabiccanvas.setactiveobject(fabictext); fabictext.enterediting() fabictext.hiddentextarea.focus(); });
<script src="https://rawgit.com/kangax/fabric.js/v1.4.5/dist/fabric.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <canvas id="canvas" width="400" height="400" class="canvas"></canvas>
Comments
Post a Comment