咱的刮刮乐
2015-11-28 12:01
302 查看
一步步写成
1、第一步
刮刮乐基本做法:用canvas画一条线,想办法让画的这条线透明,显示被遮住的内容。故第一步就是画这条线
View Code
看我的100万大奖
1、第一步
刮刮乐基本做法:用canvas画一条线,想办法让画的这条线透明,显示被遮住的内容。故第一步就是画这条线
<!doctype html> <html> <head> <title>canvas paint</title> <style> .wrap{width:1200px;margin:60px auto;background:#386077;height:500px;padding-top:60px;} .card{position:relative;margin:60px auto;width:400px;height:150px;} .default{text-align:center;line-height:150px;color:#ff5400;font-family:Arial;font-size:24px;} #twrap{width:100%;height:100%;} canvas{position:absolute;top:0;left:0;} </style> </head> <body> <div class="wrap"> <div class="card"> <div id="twrap"></div> <canvas width=400 height=150 id="canvas"></canvas> </div> </div> <script> var coverColor = '#bab4a8', w = 20, text = document.createElement('div'); text.className='default'; text.innerHTML='恭喜您,中了一百万大奖!'; var c = canvas.getContext('2d'); c.globalCompositeOperation = 'source-over'; c.fillStyle = coverColor; c.fillRect(0,0,400,150); c.font = '40px Arial'; c.fillStyle = '#666'; c.measureText(''); c.fillText('刮刮乐', 135, 90); c.globalCompositeOperation = 'destination-out'; c.lineJoin = 'round'; c.lineCap = 'round'; c.lineWidth = w || 30; c.strokeStyle = 'rgba(0,0,0,255)'; c.beginPath(); twrap.appendChild(text); var orignx, origny, startx, starty, offsetx = canvas.getBoundingClientRect().left, offsety = canvas.getBoundingClientRect().top; function mousedown(e){ orignx = e.clientX; origny = e.clientY; startx = orignx - offsetx; starty = origny - offsety; c.moveTo(startx, starty); canvas.addEventListener('mousemove', mousemove, false); canvas.addEventListener('mouseup', mouseup, false); } function mousemove(e){ var x = e.clientX - offsetx, y = e.clientY - offsety; c.lineTo(x, y); console.log(x + ", " + y); c.stroke(); } function mouseup(){ canvas.removeEventListener('mousemove', mousemove, false); canvas.removeEventListener('mouseup', mouseup, false); c.stroke(); } canvas.addEventListener('mousedown', mousedown, false); </script> </body> </html>
View Code
看我的100万大奖
相关文章推荐
- 逻辑运算的化简
- 152 You have enabled backup optimization for the RMAN environment. Identify two criteria on which RM
- 计算机网络原理入门
- C语言去掉字符串中的数字
- subclipse 对应 Subversion 版本
- windows10安装Scrapy遇到的问题
- 队列的基本操作
- JAVA中的包(Package)
- opencv中的BFMatcher和FlannBasedMatcher的区别
- 项目经理需要具备四种基本素质及八大管理技能
- 在eclipse中,如何添加现有java类文件或包文件到工程中?
- 手把手入门神经网络系列(1)_从初等数学的角度初探神经网络
- [DIY与计算机]推荐配件的一些依据
- POJ3267 DP
- 手把手入门神经网络系列(1)_从初等数学的角度初探神经网络
- java泛型总结2-2 面试题总结
- Android成长(三)——页面布局
- CCBPM 同表单分合流说明
- 调出 macbook pro第一次出现的“设置助理”
- 1049. Counting Ones