File: animation-additive-simple.html

package info (click to toggle)
node-zrender 5.4.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,588 kB
  • sloc: javascript: 1,259; makefile: 2
file content (87 lines) | stat: -rw-r--r-- 2,210 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Animation</title>
    <script src="../dist/zrender.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style>
        html, body, #main {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <div id="main"></div>
    <script type="text/javascript">
        var main = document.getElementById('main');
        // 初始化zrender
        var zr = zrender.init(main);

        function createHexogon(text) {
            return new zrender.Isogon({
                x: 150,
                y: 200,
                shape: {
                    cx: 0,
                    cy: 0,
                    r: 100,
                    n: 6
                },
                style: {
                    fill: 'red',
                    lineWidth: 5
                },
                textContent: new zrender.Text({
                    style: {
                        fill: 'white',
                        text
                    }
                })
            });
        }
        var hexogonAdditive = createHexogon('Additive');
        zr.add(hexogonAdditive);

        var hexogonNormal = createHexogon('Normal');
        zr.add(hexogonNormal);
        hexogonNormal.x = 400;


        let rotation = 0;
        let sign = 1;
        let scale = 1;

        window.onclick = function () {
            const rand = (Math.random() * 3) + 10;
            rotation += rand * sign;

            const scaleRand = Math.random() * 1;
            scale += scaleRand * sign;
            scale += scaleRand * sign;

            sign = -sign;

            hexogonAdditive.animateTo({
                rotation,
                scaleX: scale,
                scaleY: scale
            }, {
                duration: 2000,
                additive: true,
                easing: 'cubicInOut'
            });

            hexogonNormal.animateTo({
                rotation,
                scaleX: scale,
                scaleY: scale
            }, {
                duration: 2000,
                easing: 'cubicInOut'
            });
        }
    </script>
</body>
</html>