HTML5技术

HTML5 动画演示

字号+ 作者: 来源:OSCHINA    2014-11-17 18:29 我要评论( )

http://www.codeproject.com/KB/HTML/HTML5Animations.aspxHTML代码!DOCTYPE htmlhtml lang=enheadmeta charset=UTF-8/titleAnimations in HTML5 using the canvas element/titlescri...

http://www.codeproject.com/KB/HTML/HTML5Animations.aspx

HTML代码

 

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Animations in HTML5 using the canvas element</title>
<script></script>
</head>
<body>
<canvas id="canvas" width="1000" height="600">Your browser does not support the
<code>&lt;canvas&gt;</code>-element. Please think about updating your browser!</canvas>
<div id="controls">
<button type="button" onclick="speed(-0.1);">Slower</button>
<button type="button" onclick="play(this);">Play</button>
<button type="button" onclick="speed(+0.1);">Faster</button>
</div>
</body>
</html>

 

JS代码

 

function drawCanvas() {
 c.clearRect(0, 0, c.canvas.width, c.canvas.height); // Clear the (displayed)
       // canvas to avoid errors
 c.save();  // Saves the current state of properties (coordinates!)
 drawGrass();  // Draws the background (grass)
 c.translate(carX, 0); // Does some coordinate transformation
 drawCar();  // Draws the car (redraws hidden canvas)
 c.drawImage(w.canvas, 0, carY); // Draws the car actually to visible canvas
 c.restore(); // Restores to last saved state (original coordinates!)
 carX += dx;  // Increases the position by the dx we set per time
 carAlpha += dx / radius; // Increases the angle of the tires by the ratio

 if(carX > c.canvas.width) // We keep some periodic boundary conditions
  carX = -carWidth - 10; // We could also reverse the speed dx *= -1;
}

\

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTML5 进阶系列:拖放 API 实现拖放排序 - _林鑫

    HTML5 进阶系列:拖放 API 实现拖放排序 - _林鑫

    2017-05-02 11:02

  • HTML5 进阶系列:indexedDB 数据库 - _林鑫

    HTML5 进阶系列:indexedDB 数据库 - _林鑫

    2017-04-27 14:02

  • HTML5 高级系列:web Storage - _林鑫

    HTML5 高级系列:web Storage - _林鑫

    2017-04-27 14:01

  • HTML5和CSS3 - 奔跑在起跑线佼佼者

    HTML5和CSS3 - 奔跑在起跑线佼佼者

    2017-04-20 13:00

网友点评
a