canvas教程

HTML5 Canvas Spinner

字号+ 作者:H5之家 来源:H5之家 2017-04-10 09:00 我要评论( )

HTML5 Canvas Spinner,scriptsrc=

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript">

var canvas = document.getElementById('spinner'); var context = canvas.getContext('2d'); var start = new Date(); var lines = 16,

cW = context.canvas.width, cH = context.canvas.height;

var draw = function() { var rotation = parseInt(((new Date() - start) / 1000) * lines) / lines; context.save(); context.clearRect(0, 0, cW, cH); context.translate(cW / 2, cH / 2); context.rotate(Math.PI * 2 * rotation); for (var i = 0; i < lines; i++) {

context.beginPath(); context.rotate(Math.PI * 2 / lines); context.moveTo(cW / 10, 0); context.lineTo(cW / 4, 0); context.lineWidth = cW / 30; context.strokeStyle = "rgba(0, 0, 0," + i / lines + ")"; context.stroke(); } context.restore();

}; window.setInterval(draw, 1000 / 30);

 

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

相关文章
  • Canvas画图-鼠标移动图形

    Canvas画图-鼠标移动图形

    2017-04-04 09:08

  • Canvas 绘制地板

    Canvas 绘制地板

    2017-03-19 17:02

  • canvas动画―圆形扩散、运动轨迹

    canvas动画―圆形扩散、运动轨迹

    2017-03-05 08:02

  • Canvas学习:绘制线段

    Canvas学习:绘制线段

    2017-03-04 12:00

网友点评
o