Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I try to bind a click event on symbol in a svg. When a element spinns in the symbol, the click event is not fired, stops/pauses the animation, the click event fires.

How can i fix this, that the click events get fired every time i click on it, regardless if the animations run or not.

.as-console-wrapper{
display: none!important;
}
<!doctype html>
<html lang="de">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <title>Schematic</title>


    <script src="https://cdn.jsdelivr.net/npm/@svgdotjs/svg.js@3.0/dist/svg.min.js"></script>
    <!--<script src="assets/js/vue.min.js"></script>-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.12/vue.common.dev.min.js"></script>


    <script>

        const color = {
            blue: "#007bff",
            indigo: "#6610f2",
            purple: "#6f42c1",
            pink: "#e83e8c",
            red: "#dc3545",
            orange: "#fd7e14",
            yellow: "#ffc107",
            green: "#28a745",
            teal: "#20c997",
            cyan: "#17a2b8",
            white: "#fff",
            gray: "#6c757d",
            "gray-dark": "#343a40",
            primary: "#007bff",
            secondary: "#6c757d",
            success: "#28a745",
            info: "#17a2b8",
            warning: "#ffc107",
            danger: "#dc3545",
            light: "#f8f9fa",
            dark: "#343a40"
        };



        let baseColor = {
            background: "#000",
            "fill-opacity": 0.5,
            stroke: color.white,
            "stroke-width": 1,
            "stroke-opacity": 0.5
        };

        let pipeColor = {
            fill: color.blue,
            opacity: 1
        };

        let pumpColor = {
            fill: color.gray,
            "fill-opacity": 0.8
        }

        document.addEventListener("DOMContentLoaded", () => {

            // parent drawing
            let draw = SVG().addTo('#schematic').size("100%", 500);



            let pumpGroup = draw.symbol();


            pumpGroup.click(function () {
                alert("Pump clicked!");
            });


            let height = 50;
            let radius = 30;

            let chase = pumpGroup.rect(80, height).attr(baseColor).move(0, 0);  // 520, 370

            let motor1 = pumpGroup.circle(radius).attr(pumpColor).move(45, (height / 2) - radius / 2);   // 525, 380
            let motor2 = pumpGroup.circle(radius).attr(pumpColor).move(5, (height / 2) - radius / 2);   // 565, 380

            let fan1 = pumpGroup.image("https://cdn0.iconfinder.com/data/icons/screw/512/fan-ventilator-propeller-rotor-motion-512.png").scale(0.05).move(940, 240); //.animate().rotate(360, 256 + 940, 256 + 240).loop();
            let fan2 = pumpGroup.image("https://cdn0.iconfinder.com/data/icons/screw/512/fan-ventilator-propeller-rotor-motion-512.png").scale(0.05).move(140, 240);
            // 


            // 1 = slave, 2 = master
            let fant1Runner = fan1.animate(1500).ease("-").rotate(360, 256 + 940, 256 + 240).loop().timeline().pause();
            let fant2Runner = fan2.animate(1500).ease("-").rotate(360, 256 + 140, 256 + 240).loop().timeline().pause();


            setInterval(() => {

                fant2Runner.play();
                fant1Runner.play();

                setTimeout(() => {
                    fant2Runner.pause();
                    fant1Runner.pause();
                }, 2500)

            }, 5000);


            draw.use(pumpGroup).move(10, 10).click(() => {
                alert("Clicked on pump!");
            });



        });

    </script>


</head>

<body>
    <div id="app">
        <div id="schematic"></div>
    </div>
</body>

</html>
question from:https://stackoverflow.com/questions/66046108/svg-js-click-event-does-not-fire-when-animation-is-running

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
256 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...