File tree Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Expand file tree Collapse file tree 2 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 1
1
<svelte:options accessors ={true } />
2
2
3
3
<script lang =" ts" >
4
- import { afterUpdate , createEventDispatcher } from " svelte" ;
4
+ import { afterUpdate , createEventDispatcher , onDestroy } from " svelte" ;
5
5
import type { ISourceOptions } from " tsparticles-engine" ;
6
6
import { tsParticles } from " tsparticles-engine" ;
7
7
21
21
22
22
let oldId = id ;
23
23
24
- afterUpdate (async () => {
25
- tsParticles .init ();
26
-
27
- if (particlesInit ) {
28
- await particlesInit (tsParticles );
29
- }
30
-
24
+ function destroyOldContainer()
25
+ {
31
26
if (oldId ) {
32
27
const oldContainer = tsParticles .dom ().find (c => c .id === oldId );
33
28
34
29
if (oldContainer ) {
35
30
oldContainer .destroy ();
36
31
}
37
32
}
33
+ }
34
+
35
+ afterUpdate (async () => {
36
+ tsParticles .init ();
37
+
38
+ if (particlesInit ) {
39
+ await particlesInit (tsParticles );
40
+ }
41
+
42
+ destroyOldContainer ();
38
43
39
44
if (id ) {
40
45
const cb = container => {
64
69
});
65
70
}
66
71
});
72
+
73
+ onDestroy (destroyOldContainer );
67
74
</script >
68
75
69
76
<div {id } class ={cssClass } {style } />
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ declare module "svelte-particles" {
10
10
url ?: string ;
11
11
id ?: string ;
12
12
class ?: string ;
13
+ style ?: string ;
13
14
particlesInit : ( engine : Engine ) => Promise < void > ;
14
15
} ;
15
16
type ParticlesEvents = CustomEventWrapper < {
You can’t perform that action at this time.
0 commit comments