h5lock

功能描述

html5手势解锁插件H5lock

快速使用

  1. 调用js文件
  2. <script type="text/javascript" src="libs/H5lock.js"></script>
  3. js调用插件
  4. new H5lock({
  5. chooseType: 3
  6. }).init();
  7. window.H5lock = function(obj) {
  8. this.height = obj.height;
  9. this.width = obj.width;
  10. this.chooseType = Number(window.localStorage.getItem('chooseType')) || obj.chooseType;
  11. };
  12. H5lock.prototype.storePass = function(psw) {
  13. if (this.pswObj.step == 1) {
  14. if (this.checkPass(this.pswObj.fpassword, psw)) {
  15. this.pswObj.step = 2;
  16. this.pswObj.spassword = psw;
  17. document.getElementById('title').innerHTML = '密码保存成功';
  18. this.drawStatusPoint('#2CFF26');
  19. window.localStorage.setItem('passwordxx', JSON.stringify(this.pswObj.spassword));
  20. window.localStorage.setItem('chooseType', this.chooseType);
  21. } else {
  22. document.getElementById('title').innerHTML = '两次不一致,重新输入';
  23. this.drawStatusPoint('red');
  24. delete this.pswObj.step;
  25. }
  26. } else if (this.pswObj.step == 2) {
  27. if (this.checkPass(this.pswObj.spassword, psw)) {
  28. document.getElementById('title').innerHTML = '解锁成功';
  29. this.drawStatusPoint('#2CFF26');
  30. } else {
  31. this.drawStatusPoint('red');
  32. document.getElementById('title').innerHTML = '解锁失败';
  33. }
  34. } else {
  35. this.pswObj.step = 1;
  36. this.pswObj.fpassword = psw;
  37. document.getElementById('title').innerHTML = '再次输入';
  38. }
  39. }
  40. H5lock.prototype.updatePassword = function() {
  41. window.localStorage.removeItem('passwordxx');
  42. window.localStorage.removeItem('chooseType');
  43. this.pswObj = {};
  44. document.getElementById('title').innerHTML = '绘制解锁图案';
  45. this.reset();
  46. }
  47. H5lock.prototype.initDom = function() {
  48. var wrap = document.createElement('div');
  49. var str = '<h4 id="title" class="title">绘制解锁图案</h4>' + '<a id="updatePassword" style="position: absolute;right: 5px;top: 5px;color:#fff;font-size: 10px;display:none;">重置密码</a>' + '<canvas id="canvas" width="300" height="300" style="display: inline-block;margin-top: 15px;"></canvas>';
  50. wrap.setAttribute('style', 'position: absolute;top:0;left:0;right:0;bottom:0;');
  51. wrap.innerHTML = str;
  52. document.body.appendChild(wrap);
  53. }

特别说明