GithubHelp home page GithubHelp logo

barrior / jparticles Goto Github PK

View Code? Open in Web Editor NEW
479.0 12.0 35.0 1.74 MB

A lightweight, efficient and easy-to-use Canvas library for building some cool particle effects.

Home Page: https://jparticles.js.org

License: MIT License

JavaScript 12.12% TypeScript 87.88%
particle-effects javascript frontend particles canvas-particles loading-animation snow-effect wave-effect liquidfill

jparticles's Issues

用JParticles做轮播图效果时,第二张轮播图之后的高度全部变成了100px固定值

使用layui+JParticles想要实现一个轮播图的粒子运动效果,同时放置了3个JParticles对象,但是出现的效果是:第一张很正常,第二张和第三章图渲染出来的canvas高度和宽度都只有100,这个是为什么?渲染出来的canvas如下:
<canvas style="display: block; background: rgba(0, 0, 0, 0);" width="100" height="100"></canvas>

html代码如下:

        <div class="layui-carousel " width="100%" height="600px" id="demo" lay-filter="login">
            <div carousel-item>
                <div>
                    <div class="jp1"></div>
                </div>
                <div>
                    <div class="jp2"></div>
                </div>
                <div>
                    <div class="jp3"></div>
                </div>
            </div>
        </div>
            //粒子线条
            $(".jp1").jParticle({
                background: "green",//背景颜色
                color: "#fff",//粒子和连线的颜色
                particlesNumber:100,//粒子数量
                //disableLinks:true,//禁止粒子间连线
                //disableMouse:true,//禁止粒子间连线(鼠标)
                particle: {
                    minSize: 1,//最小粒子
                    maxSize: 3,//最大粒子
                    speed: 30,//粒子的动画速度
                }
            });
            $(".jp2").jParticle({
                background: "red",//背景颜色
                color: "#fff",//粒子和连线的颜色
                particlesNumber:100,//粒子数量
                //disableLinks:true,//禁止粒子间连线
                //disableMouse:true,//禁止粒子间连线(鼠标)
                particle: {
                    minSize: 1,//最小粒子
                    maxSize: 3,//最大粒子
                    speed: 30,//粒子的动画速度
                }
            });

使用问题

使用Vue引入
代码:

import { Particle } from "jparticles";


 new Particle.WaveLoading('#mainLoad', {
      fillColor: '#27C9E5',
      crestHeight: 5,
      crestCount: 3,
      speed: 0.2,
      // 加载进度文本格式为空字符串时,不显示进度文本
      textFormatter: '',
      // 取消边框圆角
      borderRadius: '',
      // 设置遮罩图片,实现遮罩效果(如果希望防止图片闪烁,可提前加载完图片后再创建特效)
      mask: 'https://raw.githubusercontent.com/Barrior/assets/main/github-logo-text.svg',
  })

报错:
jparticles__WEBPACK_IMPORTED_MODULE_2__.Particle.WaveLoading is not a constructor"

found in

jparticles__WEBPACK_IMPORTED_MODULE_2__.Particle.WaveLoading is not a constructor

直接使用
new Particle('#mainLoad', { fillColor: '#27C9E5', crestHeight: 5, crestCount: 3, speed: 0.2, // 加载进度文本格式为空字符串时,不显示进度文本 textFormatter: '', // 取消边框圆角 borderRadius: '', // 设置遮罩图片,实现遮罩效果(如果希望防止图片闪烁,可提前加载完图片后再创建特效) mask: 'https://raw.githubusercontent.com/Barrior/assets/main/github-logo-text.svg', })

是可以的,但是其他效果都是报错,我网上也查不到相关问题,请作者大大回复下我,谢谢。

Next.js Error: ReferenceError: window is not defined

I have recently used this package for adding particles animation. I used it in React (Next.js) . i got this error when trying to use it.

Screenshot from 2024-01-20 17-57-21

node_modules/jparticles/lib/common/constants.js (6:31) @ window ⨯ ReferenceError: window is not defined

Here is my Next.js Component

"use client";
import { Particle } from 'jparticles';
import React, { memo, useEffect } from 'react'

const ParticleEffect = () => {
    if(typeof window !== 'undefined')
{
// Your client-side code that uses window goes here
}
    useEffect(()=>{
        new Particle("#demo", {
          color: "#004AAD",
          lineShape: "spider",
          range: 200,
          proximity: 100,
        });
      },[]);
  return (
    typeof window !== 'undefined' &&  <div className="absolute w-full h-3/4" id="demo"></div>
  )
}

export default memo(ParticleEffect);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.