adobe-webplatform / Snap.svg

The JavaScript library for modern SVG graphics.
http://snapsvg.io
Apache License 2.0
13.91k stars 1.15k forks source link

Constantly create new nodes #632

Closed andyTsing closed 4 years ago

andyTsing commented 4 years ago

图片 图片

render() {
    return (
        <React.Fragment>
                    <div ref = { this.setSVGRef } />
        </React.Fragment>
    );
}
onSVGLoaded = data => {
    let lElement = Snap(this.refSVG);
    lElement.append(data);
}
 Snap.load('images/Printer.svg', this.onSVGLoaded);

lElement.append(data); how to clear it? lElement.remove();?

andyTsing commented 4 years ago

I found the reason: because there is no call to stop the animation(When the component is componentWillUnmount(), there are running animation frames), and there are no svg instances on other pages, all the results of the animation are all attached to the page body.

componentWillUnmount() {
    this.AS(0X01);
    this.AS(0X00, '#H');
}

AS is a function to Stop the corresponding animation。