search

Home  >  Q&A  >  body text

javascript - 一个手势解锁的js

(function(){

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

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

<code>    window.H5lock = function(obj){

        this.height = obj.height;

        this.width = obj.width;

        this.chooseType = Number(window.localStorage.getItem('chooseType')) || obj.chooseType;

    };

 

    function getDis(a, b) {

        return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));

    };

 

    H5lock.prototype.pickPoints = function(fromPt, toPt) {

        var lineLength = getDis(fromPt, toPt);

        var dir = toPt.index > fromPt.index ? 1 : -1;

 

        var len = this.restPoint.length;

        var i = dir === 1 ? 0 : (len - 1);

        var limit = dir === 1 ? len : -1;

 

        while (i !== limit) {

            var pt = this.restPoint[i];

 

            if (getDis(pt, fromPt) + getDis(pt, toPt) === lineLength) {

                this.drawPoint(pt.x, pt.y);

                this.lastPoint.push(pt);

                this.restPoint.splice(i, 1);

                if (limit > 0) {

                    i--;

                    limit--;

                }

            }

 

            i+=dir;

        }

    }

 

    H5lock.prototype.drawCle = function(x, y) { // 初始化解锁密码面板

        this.ctx.strokeStyle = '#CFE6FF';

        this.ctx.lineWidth = 2;

        this.ctx.beginPath();

        this.ctx.arc(x, y, this.r, 0, Math.PI * 2, true);

        this.ctx.closePath();

        this.ctx.stroke();

    }

    H5lock.prototype.drawPoint = function() { // 初始化圆心

        for (var i = 0 ; i < this.lastPoint.length ; i++) {

            this.ctx.fillStyle = '#CFE6FF';

            this.ctx.beginPath();

            this.ctx.arc(this.lastPoint[i].x, this.lastPoint[i].y, this.r / 2, 0, Math.PI * 2, true);

            this.ctx.closePath();

            this.ctx.fill();

        }

    }

</code>

大家讲道理大家讲道理2901 days ago691

reply all(0)I'll reply

No reply
  • Cancelreply