RaphaelJS performance with thousands of paths / rectangles

I really only care about Webkit, but should Raphael JS normally work well when creating thousands of rectangles?

In addition, I will need to handle events on each of these rectangles (yipes).

I have C ++ - a solution that works, but I would prefer to use RaphaelJS.

Thank:)

+3
source share
2 answers

I don't know anything about RaphaelJS, but I can give you a hint with this code:

<!DOCTYPE html>

<html>
    <head>
        <meta charset = "utf-8">

        <title></title>

        <script>
            window.onload = function () {
                var rectangles = 5000;

                for (var i = 0; i < rectangles; i ++) {
                    var height = 50;
                    var width = 50;

                    var canvas = document.createElement ("canvas");
                        canvas.height = height;
                        canvas.style.margin = "15px";
                        canvas.width = width;

                    canvas.addEventListener ("click", function () {
                        alert ("You like to MOVE !");
                    }, false);

                    var ctx = canvas.getContext ("2d");

                    ctx.fillStyle = "silver";
                    ctx.fillRect (0, 0, width, height)

                    document.body.appendChild (canvas);
                }

                canvas = document.body.getElementsByTagName ("canvas");

                window.setInterval (function () {
                    for (var i = 0; i < canvas.length; i ++) {
                        canvas[i].style.margin = (Math.floor (Math.random () * 16)) + "px";
                    }
                }, 100);
            }
        </script>
    </head>

    <body></body>
</html>

5000 rectangles moving with the onclick event: enter image description here

+4
source

Raphael JS, 10 000 . .

http://jsfiddle.net/jaRhY/1049/

+3

Source: https://habr.com/ru/post/1735748/


All Articles