为了研究canvas一些属性简单实现的一个小效果  代码样式不太规范 随手写的 请问喷 初学者可以看下

css代码

<style>
* {
margin: 0;
padding: 0;
} html,
body {
width: 100%;
height: 100%;
} .container {
width: 100%;
height: 100%;
position: relative;
} #box {
width: 100%;
height: 300px;
text-align: center;
line-height: 300px;
font-size: 30px;
color: mediumspringgreen;
font-weight: 900;
background: url('https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=4210473879,3554842544&fm=27&gp=0.jpg') no-repeat;
background-size: 100% 100%;
} canvas {
position: absolute;
left: 0;
top: 0;
}
</style>

 HTML代码 

 <div class="container" id="container">

         <div id="box"></div>
<canvas id="canvas"></canvas>
</div>

JS代码

  <script>
canvas.width = box.offsetWidth;
canvas.height = box.offsetHeight;
let context = canvas.getContext('2d');
//背景填充色
context.fillStyle = '#ccc';
context.fillRect(0, 0, box.offsetWidth, box.offsetHeight); //把灰色矩形当做目标对象 然后线当做源对象
//destination-out 在源图像外显示目标图像。只有源图像外的目标图像部分会被显示,源图像是透明的。
//destination-in 在源图像中显示目标图像。只有源图像内的目标图像部分会被显示,源图像是透明的。
context.globalCompositeOperation = 'destination-out'; let arr = ["一等奖", "二等奖", "三等奖", "谢谢惠顾"]; box.innerText = arr[Math.floor(Math.random() * arr.length)] canvas.addEventListener("touchstart", function (e) {
context.beginPath();
context.moveTo(e.touches[0].pageX, e.touches[0].pageY);
context.lineWidth = 20; context.lineCap = 'round';
context.lineJoin = 'round';
canvas.addEventListener("touchmove", function (e) {
context.lineTo(e.touches[0].pageX, e.touches[0].pageY);
context.stroke();
})
canvas.addEventListener("touchend", function (e) {
context.closePath(); })
})
</script>

移动端利用canvas画布简单实现刮刮乐效果的更多相关文章

  1. canvas 利用canvas中的globalCompositeOperation 绘制刮奖 效果

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <t ...

  2. pc端结合canvas实现简单签名功能

    需求:业务员做提交时要签名... 代码不多简单易懂,直接看代码 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  3. html5 利用canvas实现简单的人物走动

    最近在学习html5,其中涉及到很关键的元素canvas-画布,在网上下载了一些游戏源代码,虽然能看懂,但是想单独地针对某个功能提取出来还是有难处的,于是乎自己又上网查找了一些例子,才将超级玛丽简单的 ...

  4. 利用canvas制作简单的logo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  5. 利用Canvas实现360度浏览

    前言:最近几个月来到新公司,主要从事移动端方面的开发,有时候也挺忙挺累的,于是就好一段时间没写博客了.其实自己在这几个月里,自己对canvas以及createjs和egret都有了一定程度上的认识与掌 ...

  6. 利用canvas实现的中点Bresenham算法

    Bresenham提出的直线生成算法的基本原理是,每次在最大位移方向上走一步,而另一个方向是走步还是不走步取决于误差项的判别,具体的实现过程大家可以去问度娘.我主要是利用canvas画布技术实现了这个 ...

  7. [技术博客]海报图片生成——小程序canvas画布

    目录 背景介绍 canvas简介 代码实现 难点讲解 圆角矩形裁剪失败之PS的妙用 编码不要过硬 对过长的文字进行截取 真机首次生成时字体不对 drawImage只能使用本地图片 背景介绍 目标:利用 ...

  8. 用html5的canvas画布绘制贝塞尔曲线

    查看效果:http://keleyi.com/keleyi/phtml/html5/7.htm 完整代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHT ...

  9. HTML5-canvas实例:刮刮乐游戏

    实现方法: (1)利用canvas画布,fillRect()描绘出一个矩形(不是透明),定位盖在某个标签如div上面(这个标签写着中奖的信息) (2)globalCompositeOperation ...

随机推荐

  1. Android sqlite日期存储

    SQLite日期类型是以TEXT.REAL和INTEGER类型分别不同的格式表示的,对应如下:TEXT: "YYYY-MM-DD HH:MM:SS.SSS"REAL: 以Julia ...

  2. linux 系统开机自启执行 操作的配置

    1 linux 服务注册 service文件 在service文件中设置变量和环境变量 [Unit] Description= #服务描述 After=syslog.target #服务启动依赖 [S ...

  3. Jmeter参数化设置,多用户登录

    一.模拟多用户登录场景 如登录模式如下图所示,登录界面中需要输入:用户名.密码.验证码 用户名以及密码均是固定值,不需要做处理.验证码需要处理一下,可以后台配置成固定值,具体可以找开发咨询. 在此场景 ...

  4. 安装Access Database Engine后,提示未注册Microsoft.ACE.OLEDB.12.0

    未注册Microsoft.ACE.OLEDB.12.0 ,下载安装 Microsoft Access Database Engine:https://www.microsoft.com/en-us/d ...

  5. npm install warning: no description; no repository field

    npm install 报错:warning no description; no repository field 开始以为必须npm init,npm init在git bash(win7)里,还 ...

  6. antd Grid

    import { Row, Col } from 'antd'; <Row type="flex" //内容布局(左靠齐,右靠齐,居中) justify="star ...

  7. 根据操作系统进程号,查找sql语句

    有时需要根据操作系统编号查找正在执行的sql语句:select sess.username,sql1.SQL_TEXTfrom v$session sess,v$sqltext sql1,v$proc ...

  8. PyCharm的Debug工具栏中的Watches

    In the Watches pane you can evaluate any number of variables or expressions in the context of the cu ...

  9. MVVM的核心:双向绑定

    MVVM 模式将 Presenter 改名为 ViewModel,基本上与 MVP 模式完全一致. 唯一的区别是,它采用双向绑定(data-binding):View的变动,自动反映在 ViewMod ...

  10. 如何解决“当前上下文中不存在名称“XXXXXXXX””的问题

    如果你是用的Visual Studio 2017,如果你项目中的.cshtml文件出现编译调试一切正常,但是在设计时查看出现下面的提示时: 错误 CS0103 当前上下文中不存在名称“ViewBag” ...