File: animation-cubic-easing.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 (81 lines) | stat: -rw-r--r-- 2,327 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
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Animation Keyframe Easing</title>
    <script src="../dist/zrender.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/tweakpane@3.0.5/dist/tweakpane.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tweakpane/plugin-essentials@0.1.4/dist/tweakpane-plugin-essentials.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style>
        html, body, #main {
            width: 100%;
        }
        #main {
            height: 400px;
        }
    </style>
</head>
<body>
    <div id="main"></div>
    <h2>SVG SSR</h2>
    <div id="replay"></div>
    <script type="text/javascript">
        var main = document.getElementById('main');
        // 初始化zrender
        var zr = zrender.init(main, {
            renderer: 'svg'
        });

        var circles = [];

        for (var i = 0; i < 5; i++) {
            var circle = new zrender.Circle({
                x: 100,
                y: i * 80,
                shape: {
                    cx: 30,
                    cy: 30,
                    r: 30
                },
                style: {
                    fill: 'red',
                    lineWidth: 5
                },
            });
            zr.add(circle);
            circles.push(circle);
        }

        function startAnimation(easing) {
            circles.forEach((circle, idx) => {
                circle.x = 100;
                circle.animate('')
                    .when(1000, {
                        x: 800
                    })
                    .delay(idx * 100)
                    .start(easing);
            });

            document.getElementById('replay').innerHTML = zr.painter.renderToString();
        }

        startAnimation();

        const pane = new Tweakpane.Pane();
        pane.registerPlugin(TweakpaneEssentialsPlugin);

        pane.addBlade({
            view: 'cubicbezier',
            value: [0, 0, 1, 1],
            expanded: true,
            label: 'cubic-bezier',
            picker: 'inline',
        }).on('change', (ev) => {
            const easing = `cubic-bezier(${ev.value.x1}, ${ev.value.y1}, ${ev.value.x2}, ${ev.value.y2})`;
            startAnimation(easing);
        });
    </script>
</body>
</html>