@splatrac/vue-snowfall 1.1.2 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/useSnowfall.js +11 -4
package/package.json
CHANGED
package/src/useSnowfall.js
CHANGED
|
@@ -4,8 +4,9 @@ export function useSnowfall() {
|
|
|
4
4
|
const DEFAULT_OPTIONS = {
|
|
5
5
|
// Ranges for the random generators (same as the previous defaults)
|
|
6
6
|
timeRange: { min: 20, max: 29 }, // seconds the flake falls
|
|
7
|
-
posRange: { min:
|
|
8
|
-
sizeRange: { min: 10, max: 109 } // scale factor
|
|
7
|
+
posRange: { min: 0, max: window.innerWidth }, // % across the viewport
|
|
8
|
+
sizeRange: { min: 10, max: 109 }, // scale factor
|
|
9
|
+
maxFlakes: 100,
|
|
9
10
|
};
|
|
10
11
|
|
|
11
12
|
const addStyles = () => {
|
|
@@ -19,6 +20,7 @@ export function useSnowfall() {
|
|
|
19
20
|
width: 30px;
|
|
20
21
|
height: 30px;
|
|
21
22
|
pointer-events: none;
|
|
23
|
+
animation-fill-mode: forwards;
|
|
22
24
|
}
|
|
23
25
|
@keyframes falling {
|
|
24
26
|
0% { transform: translateX(0) translateY(0) rotate(0deg); opacity: 1; }
|
|
@@ -49,6 +51,8 @@ export function useSnowfall() {
|
|
|
49
51
|
return template.content.firstChild
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
const currentFlakeCount = () => document.querySelectorAll('.flake').length;
|
|
55
|
+
|
|
52
56
|
const createSnowflake = ({
|
|
53
57
|
timeRange,
|
|
54
58
|
posRange,
|
|
@@ -100,8 +104,11 @@ export function useSnowfall() {
|
|
|
100
104
|
if (flakeIntervalId) clearInterval(flakeIntervalId)
|
|
101
105
|
|
|
102
106
|
flakeIntervalId = setInterval(() => {
|
|
103
|
-
|
|
104
|
-
|
|
107
|
+
if (currentFlakeCount() < maxFlakes) {
|
|
108
|
+
createSnowflake(finalOptions)
|
|
109
|
+
} else {
|
|
110
|
+
removeSnowflakes()
|
|
111
|
+
}
|
|
105
112
|
}, interval)
|
|
106
113
|
}
|
|
107
114
|
|