HTML5 move canvas object

I have 2 canvases created on one canvas. Is it possible to drag a little black around? I want to make it draggable, but I cannot find any online tutorial or demo on this. Is it possible? I looked at Canvas moveTo or transitions, but I could not get it to work.

Code here http://jsfiddle.net/35P9F/2/

  var ctx = document.getElementById('canvas').getContext('2d');

  var radgrad3 = ctx.createLinearGradient(255,10,0,180,80,190);
  radgrad3.addColorStop(0, '#00C9FF');
  radgrad3.addColorStop(1, 'red');

  ctx.fillStyle = radgrad3;
  ctx.fillRect(0,0,255,255);



  var ctx4 = document.getElementById('canvas').getContext('2d');
  var radgrad4 = ctx4.createLinearGradient(0, 0, 0, 255);
  radgrad4.addColorStop(0, '#000000');
  radgrad4.addColorStop(1, '#ff0000');

  ctx4.fillStyle = radgrad4;
  ctx4.fillRect(0,0,25,25);

Thank.

+3
source share
2 answers

Short answer: there is no automatic way to do this.

: <canvas> " ", , , . , , . , - , , , .

, , , , . SVG - . - SVG, , HTML, , .

+10

, : Canvas

!

0

Source: https://habr.com/ru/post/1742966/


All Articles