I have the funtction that adds an image in canvas after loading
function handleImage(e) {
var reader = new FileReader();
var _this = this;
var loadImage = _this.parentElement;
var canvas = loadImage.querySelector('canvas');
var ctx = canvas.getContext("2d");
reader.onload = function(event) {
var img = new Image();
img.onload = function() {
let width_pic = 200;
let k = img.width/width_pic;
canvas.height = img.height / k;
ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, width_pic,
canvas.height);
};
img.src = event.target.result
};
reader.readAsDataURL(e.target.files[0]);
}
However I will use this function for virtual element (element that appeared by
$('button').click(function(){
$('#new-pic').html(`<p>virt</p><input class="load_ph_step" type="file"/> <canvas></canvas>`);
});
), for this element the function does not work.
I now in this sutuation in jquery is used $(document).on('click', 'selector', function(e){});
, but now I use javascript-function.