本篇文章小编给大家分享一下html5中canvas手势解锁源码解析,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
先放图
demo.html
css">
body{
text-align: center;
background: #305066;
}
h4{
color: #22C3AA;
}
index.js
(function(){
/**
* 实现画圆和划线:
* 1、添加事件touchstart、touchmove、touchend
* 2、touchstart判断是否点击的位置处于圆内getPosition,处于则初始化
* lastpoint、restPoint
* 3、touchmove做的就是:画圆drawPoint和画线drawLine
*
* 实现自动画圆的效果
* 1、检测手势移动的位置是否处于圆内
* 2、圆内的话则画圆 drawPoint
* 3、已经画过实心圆的圆,无需重复检测
*
* 实现解锁成功:
* 1、检测路径是否是对的
* 2、如果是对的就重置,圆圈变绿
* 3、不对也重置,圆圈变红
* 4、重置
*/
window.canvasLock = function(obj){
this.height = obj.height;
this.width = obj.width;
this.chooseType = obj.chooseType;
};
// js方式动态生成dom
canvasLock.prototype.initDom = function(){
var wrap = document.createElement('div');
var str = '