Input form inside canvas element

前端 未结 4 801
抹茶落季
抹茶落季 2020-12-30 06:07

I\'m wondering if there was any way to get an input from the user, preferably to a texbox (or anywhere a user can see what he\'s writting) in a canvas element through javasc

4条回答
  •  被撕碎了的回忆
    2020-12-30 06:31

    Question is a bit old, but I wanted to provide an alternative to absolute positioning. You can set the background-image (presumably to a div bigger than your textbox). Here's an example:

    HTML:

    ... 
    ...[your textbox]
    ...

    Javascript:

    $('#backDrop').css('background-image', 'url(' + document.getElementById('canvas').toDataURL() + ')');
    

    Here's a jsfiddle as an example.

    As noted here, this essentially takes a snapshot of the canvas at the point you set the background-image property. Any changes you make to the canvas after setting the background-image will not be reflected (unless you re-set it), but this is probably what you want in most cases.

提交回复
热议问题