HTML5 canvas image is not visible in chrome

后端 未结 2 1711
自闭症患者
自闭症患者 2021-01-26 08:34

I am using HTML5 canvas and putting two images there but I am facing one problem which is, one image is loaded and visible in chrome but another image is only visible in mozilla

2条回答
  •  [愿得一人]
    2021-01-26 09:31

    As onload event is asynchronous, make sure play-button is being set in the onload-handler of the base-image

    var canvas = document.getElementById('canvas');
    var context = canvas.getContext('2d');
    var x = 0;
    var y = 0;
    var width = 900;
    var height = 700;
    var imageObj = new Image();
    imageObj.onload = function() {
      context.drawImage(imageObj, x, y, width, height);
      var startImageObj = new Image();
      startImageObj.onload = function() {
        context.drawImage(startImageObj, (canvas.width - startImageObj.width) / 2, (canvas.height - startImageObj.height) / 2)
      };
      startImageObj.src = 'https://d30y9cdsu7xlg0.cloudfront.net/png/5670-200.png';
    };
    imageObj.src = 'http://img13.deviantart.net/1550/i/2011/353/4/2/mobile_game_background_by_disnie-d4jmr8r.jpg';

提交回复
热议问题