百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

snowflakes

> 编程语言
开源

❄️☃️ 正在下落的雪花

397 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

❄️☃️ 正在下落的雪花

❄️☃️ Falling snowflakes

Details

  • Only one JavaScript file
  • CSS animations
  • Responsive layout
  • Flexible settings with dynamic updates via setParams()

Examples

  • Constructor: change settings and copy code for your site
  • 3D Cube
  • ❄ Simple
  • Multicolor
  • Big
  • Blend mode
  • Layer
  • Some layers
  • Own kind
  • Own z-index

See details

Usage

bash
npm install magic-snowflakes

Without settings

Paste anywhere in your page's HTML:

xml

With settings

xml

    ...
    

    

Advanced settings

xml

    

    

    

Color with CSS

Snowflakes use SVG masks filled with currentColor. The color option sets the container's CSS color (default: #5ECDEF). Override individual snowflakes in your stylesheet:

css
.snowflake {
    color: white;
}

.snowflake:nth-child(3n) {
    color: #ff69b4;
}

You can also pass a CSS variable as the color. Updating the variable recolors existing snowflakes without recreating the instance:

css
:root {
    --snow-color: #5ECDEF;
}
javascript
new Snowflakes({ color: 'var(--snow-color)' });

Use color: 'inherit' to inherit the color of your custom container.

TypeScript or ES modules

javascript
import Snowflakes from 'magic-snowflakes';
const snowflakes = new Snowflakes();
// ...
snowflakes.stop();
// ...
snowflakes.start();
// ...
snowflakes.destroy();

API

javascript
import Snowflakes from 'magic-snowflakes';
const snowflakes = new Snowflakes();

.start()

Start or resume the animation.

.stop()

Pause the animation.

.show()

Show snowflakes.

.hide()

Hide snowflakes.

.resize()

Update the animation for the current container size.

.setParams(params)

Apply any subset of the constructor options to the existing instance:

javascript
snowflakes.setParams({ color: '#fff', speed: 2, count: 100 });

Omitted options and undefined values keep their current settings; they are not reset to constructor defaults. Values such as 0 and false are applied normally. Invalid numbers fall back to current settings. If only one size or opacity bound is supplied, it is clamped against the unchanged opposite bound. If both bounds are supplied, an inverted pair is swapped as in the constructor. Hidden and paused states are preserved unless stop is explicitly provided.

Color, opacity, speed, wind, rotation, shapes, zIndex, autoResize and stop updates preserve existing flakes. Dimension and parent container changes reuse the flakes and update the animation geometry. Changing count adds or removes only the difference, leaving retained flakes in place. Removal selects flakes randomly regardless of size; newly added flakes are inserted in size order. Speed and height changes recalculate falling duration and delay using each flake's original random delay factor.

Only changes to minSize or maxSize recreate all flakes, redistributing their sizes and stacking order and restarting their animation. The instance and its container element are reused. Unchanged settings do not recreate flakes. Calls after destroy() have no effect.

.destroy()

Remove the snowflakes and release the instance's resources.

Different Builds

The dist/ directory of the npm package contains the following builds:

Type Filename Description
Full (UMD) snowflakes.js
Full (UMD, production) snowflakes.min.js
Full auto snowflakes.auto.js Without API
Full auto (production) snowflakes.auto.min.js Without API
ES module snowflakes.esm.js
Light (UMD) snowflakes.light.js Without SVG images
Light (UMD, production) snowflakes.light.min.js Without SVG images

Development

Source files are grouped by responsibility:

  • src/index.ts exposes the public API; src/index.auto.ts is the automatic startup entry point.
  • src/core/ contains the main class, individual flakes, options, defaults and normalization.
  • src/animation/ contains calculations and keyframes.
  • src/utils/ contains shared DOM and math helpers.
  • src/styles/ contains stylesheet management and CSS; src/assets/snowflakes/ contains SVG masks.
  • examples/constructor/src/ contains the playground and code preview.
  • tests/unit/, tests/integration/ and tests/types/ contain the existing test suites.
  • scripts/inject-styles.mjs injects the built CSS; docs/assets/ contains documentation images.

Build output keeps its existing paths: dist/snowflakes*.js, dist/index.d.ts, dist/main.css, dist/types.css and examples/constructor/dist/index.{js,css}. Previously published declaration paths remain available through compatibility re-exports. Example URLs, including examples/constructor/, remain unchanged.

Command Purpose
npm run build:lib Clean and build the library, declarations, CSS and minified bundles in dist/
npm run build:examples Clean and build the constructor in examples/constructor/dist/
npm run build Build the library, then the examples
npm run typecheck:lib Check library types independently of the constructor
npm run typecheck:examples Check constructor types and its imported library sources
npm test Run ESLint, all type checks and the existing Jest suites
npm run test:build Verify independent builds and packaging in temporary project copies

Both builds work from a clean checkout with dependencies installed. The library build does not read constructor sources or output. The examples build processes library CSS from source and does not require or modify dist/.

tsconfig.base.json contains shared compiler settings. tsconfig.json and rollup.config.mjs cover the library; examples/constructor/tsconfig.json and rollup.examples.config.mjs cover the constructor. The prepare lifecycle used by installation and packaging runs build:lib; CI and Pages build examples explicitly. The lower-level make, make:ts, make:css and inject:css commands operate on the library.

bash
git clone [email protected]:hcodes/snowflakes.git ./snowflakes
cd ./snowflakes

npm i
npm run build
npm test

open ./examples/

License

MIT License

Friends

  • Check device online

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptchristmasfalling-snowflakeshappy-new-yearsnowflake

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言