Store images in Javascript object

前端 未结 3 1451
谎友^
谎友^ 2020-12-04 10:36

I am not sure if this is possible, but I want to store an image in a JavaScript variable or an object and when the page loads, I want to make those images appear where desir

3条回答
  •  眼角桃花
    2020-12-04 10:46

    You can simply use

    var img = new Image();
    img.src = "http://yourimage.jpg";
    

    to create a DOM image.

    A DOM image is an object in memory that contains the image binary form, so there's no need to convert it back to an image since it's already one.

提交回复
热议问题