lundi 23 février 2015

HTML5 Canvas Animated Images Don't Load in Mobile Device Browsers


var c = document.getElementById("c");
var ctx = c.getContext("2d");

/*$("canvas").mousemove(function (event) {
imj.x = event.pageX - 80;
imj.y = event.pageY - 80;
});*/

function img(image, x, y, sorc) {
image.onload = function () {
ctx.drawImage(image, x, y);
}
image.src = sorc;
}

var imj = {
img: new Image(),
x: 0,
y: 0
};
function render() {
ctx.clearRect(0, 0, c.width, c.height);
img(imj.img, imj.x, imj.y, "http://ift.tt/1A60oA1");
imj.x += 1;
imj.y += 1;
}

setInterval(function () { render(); }, 40);


When I load this code (along with the HTML), it works fine on my laptop, but on my Nexus 7, the image shows up once and then disappears. And if I make the image stay in place, it does show up on my tablet. Why? (you can try it yourself or see all the code here http://ift.tt/1A60mrH)


Aucun commentaire:

Enregistrer un commentaire