A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 刘亚中 中级黑马   /  2012-3-11 23:35  /  2928 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

前端时间看到某学校的查看成绩的网站是通过刮刮卡的形式来实现的!觉得比较有趣,于是想到了html5的画布功能,做了一个,代码如下:
希望对大家有帮助!
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.     <title>画布练习</title>
  5.     <style type="text/css">
  6.         #score, canvas
  7.         {
  8.             position:absolute;
  9.             top:50px;
  10.             left:50px;
  11.             cursor:pointer;
  12.             z-index:100;
  13.         }
  14.         #score
  15.         {
  16.             display:block;
  17.             height:100px;
  18.             width:100px;
  19.             background:#EFEFEF;
  20.             color:#ff6a00;
  21.             font-family:Consolas;
  22.             font-size:30px;
  23.             font-weight:bold;
  24.             z-index:-100;
  25.         }
  26.     </style>
  27. </head>
  28. <body style="text-align:center">
  29.     <canvas id="canvas_background" height="100" width="100"></canvas>
  30.     <canvas id="score"></canvas>
  31.     <script src="../Scripts/jQuery-1.7.1.js" type="text/javascript"></script>
  32.     <script>
  33.         function createGG(score) {
  34.             var canvas_score = document.querySelector('#score'), ctx_score = canvas_score.getContext('2d');
  35.             ctx_score.font = '400 82px Consolas';
  36.             ctx_score.fillStyle = 'Red';
  37.             ctx_score.fillText(parseInt(score), 100, 100);

  38.             var canvas = document.querySelector('#canvas_background'), ctx = canvas.getContext('2d');
  39.             ctx.fillStyle = 'rgb(22, 22, 22)';
  40.             ctx.fillRect(0, 0, ctx.canvas.height, ctx.canvas.width);

  41.             //事件
  42.             window.onmousedown = function (event) {
  43.                 canvas.onmousemove = function (event) {
  44.                     ctx.clearRect(event.offsetX, event.offsetY, 20, 20);
  45.                 }
  46.             }

  47.             window.onmouseup = function () {
  48.                 canvas.onmousemove = function (event){ };
  49.             }
  50.         }
  51.     </script>
  52. </body>
  53. </html>
复制代码

评分

参与人数 1技术分 +2 收起 理由
宋天琪 + 2

查看全部评分

1 个回复

倒序浏览
使用的时候执行createGG函数 里面的score为成绩的分数
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马