http://ernestdelgado.com/public-tests/gifoncanvas/

canvas加载gif

<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Animated Gif on Canvas</title>
<style type="text/css" media="screen">

body { color: #222; font: 75% "Lucida Grande", "Trebuchet MS", Verdana, sans-serif; margin: 0 auto; width: 750px; }
img { border: 3px solid yellow; }
canvas { border: 3px solid red; }
.ex-group { border-bottom: 1px solid #ccc; padding-bottom: 15px; }
</style></head>


<body>
<div class="ex-group">
<img >

(function() {
var dx = 0;
drawGif = {
draw: function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var imageObj = document.getElementById("ex-animated-sprite-gif");

//if(dx >= 550){
this.clearCanvas("myCanvas");
// dx=0;
//}
// dx+=50;
context.drawImage(imageObj, dx, 0,50, 50);
},
clearCanvas: function(canvasEl) {
var cv = document.getElementById(canvasEl);
cv.getContext('2d').clearRect(0, 0, cv.width, cv.height);
}


}
})()

window.onload = (function() {
setInterval(function(){
drawGif.draw();
},150);
});
</script>

 

</body>
</html>

相关文章:

  • 2021-04-13
  • 2018-08-21
  • 2021-12-04
  • 2021-10-07
  • 2021-12-16
  • 2022-01-01
  • 2021-10-18
猜你喜欢
  • 2020-02-28
  • 2020-06-14
  • 2017-11-23
  • 2021-11-17
  • 2021-08-08
  • 2021-05-30
  • 2021-10-18
  • 2021-09-08
相关资源
相似解决方案