 
						ScratchCard是一款支持移动手机的HTML5 canvas刮刮卡插件。该刮刮卡插件支持移动触摸事件,提供刮卡的回调函数,简单易用,效果非常不错。
在页面中引入Scratch.js文件。
| 1 | <scripttype="text/javascript"src="js/Scratch.js"></script> | 
HTML结构
使用下面的HTML结构来制作一个刮刮卡:
| 1 2 3 4 5 6 | <divclass="scratch_container">  <divclass="scratch_viewport">    <!-- result picture -->    <canvasid="js-scratch-canvas"></canvas>  </div></div> | 
CSS样式
为刮刮卡添加下面的CSS样式。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | .scratch_container {  position: relative;  margin: 0auto;  max-width: 1024px;} .scratch_viewport {  position: relative;  width: 250px;  height: 250px;  margin: 0auto;  z-index: 0;} .scratch_picture-under {  position: absolute;  top: 0;  left: 0;  display: block;  z-index: -1;} .scratch_container canvas {  position: relative;  width: 100%;  height: auto;  z-index: 1;} | 
初始化插件
在页面页面底部<body>标记结束之前,使用下面的代码来实例化一个刮刮卡对象。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | varscratch = newScratch({    canvasId: 'js-scratch-canvas',    imageBackground: 'loose.jpg',    pictureOver: 'foreground.jpg',    cursor: {        png: 'piece.png',        cur: 'piece.cur',        x: '20',        y: '17'    },    radius: 20,    nPoints: 100,    percent: 50,    callback: function() {      alert('I am Callback.');    },    pointSize: { x: 3, y: 3}}); | 
配置参数
该Canvas刮刮卡插件的可用配置参数有:
canvasId:canvas的id。
imageBackground:背景图片(刮开后呈现的图片)。
pictureOver:前景图片。
sceneWidth:canvas的宽度。
sceneHeight:canvas的高度。
radius:清除区域的半径。
nPoints:清除区域的杂点数量。
percent:在清除多少区域之后清空canvas。
cursor:光标。
png:png格式的光标。
x:Move position x。
y:Move position y。
cur:cur格式的光标(IE使用)。
特别申明:
			本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
			本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
			如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com