jQuery创建粒子背景 浮力

  • 源码大小:12.34KB
  • 所需积分:1积分
  • 源码编号:19JP-3614
  • 浏览次数:753次
  • 最后更新:2023年07月02日
  • 所属栏目:动画
本站默认解压密码:19jp.com 或 19jp_com

简介

Buoyant是一个小的(缩小了2kb)jQuery插件,用于从任何CSS形状或图像创建动画粒子,这些形状或图像在激活时在网页背景上随机移动。

参见:

  • JavaScript中的10个最佳粒子系统/效果

如何使用它:

1.在jQuery库之后加载Buoyant插件的缩小版。

  1. <script src="/path/to/cdn/jquery.min.js"></script>
  2. <script src="/path/to/dist/jquery.buoyant.min.js"></script>

2.将插件附加到目标元素,并为粒子定义图像或CSS形状。

  1. $("body").buoyant({
  2. imgSrc: 'particle.png'
  3. });
  4.  
  5. // or
  6. $("body").buoyant({
  7. elementClass: 'myShape'
  8. });
  1. .myShape {
  2. /* CSS shape here */
  3. }

3.设置粒子的最小/最大尺寸。

  1. $("body").buoyant({
  2. minRadius: 10,
  3. maxRadius: 40
  4. });

4.设置粒子的最小/最大动画速度。

  1. $("body").buoyant({
  2. minSpeed: 20,
  3. maxSpeed: 70
  4. });

5.设置要生成的粒子数。

  1. $("body").buoyant({
  2. numberOfItems: 4
  3. });

6.具有默认值的完整配置选项。

  1. $("body").buoyant({
  2. containerClass: "buoyant-container",
  3. parentClass: 'buoyant-parent',
  4. elementClass: '',
  5. imgSrc: '',
  6. width: 50,
  7. height: -1,
  8. backgroundColor: "black",
  9. fps: 60,
  10. numberOfItems: 4,
  11. minRadius: 10,
  12. maxRadius: 40,
  13. minSpeed: 20,
  14. maxSpeed: 70,
  15. collisionEfficiency: 1,
  16. gravity: 0,
  17. trails: false,
  18. colliding: false
  19. });

更新日志:

2022-04-15

  • 使现代化

预览截图