Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for strict mode aka make it work in modules without breaking normal mode #508

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Dark-Bob
Copy link

@Dark-Bob Dark-Bob commented Jan 3, 2023

Swapped out arguments.callee for a simple recursive call, so the script can run in strict mode ie: inside modules but it doesn't break running outside a module.

Usage inside a module:

import "https://code.jquery.com/jquery-3.2.1.js";
import "<path>/particles.js"

window.particlesJS("particle-canvas-green", {
            particles: {
                number: {
                    value: 100,
                    ...
});

Also added canvasResize and return the pJS object, so canvases can be resized explicitly. This can allow elements that are initially not displayed to host particles and then once they are displayed, we can call this and have the particles work as expected rather than occupy a 0x0 canvas.

import "https://code.jquery.com/jquery-3.2.1.js";
import "<path>/particles.js"

const particle_js_green = window.particlesJS("transition-particle-canvas-green", {
            particles: {
                number: {
                    value: 100,
                    ...
});

// Then on event
particle_js_green.canvasResize();

… inside modules. Also added canvasResize and return the pJS object, so canvases can be resized explicitly.
@matteobruni
Copy link

Duplicate of #194 and #65 but the project seems abandoned. Maybe an alternative?

@Dark-Bob
Copy link
Author

Dark-Bob commented Jan 4, 2023

Thanks Matteo, I'll leave it open since it has the canvas resize fix too but yeah if this repo is dead and I need to make any more improvements, I'll check yours out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants