@melt-js/comps-vue2 2026.11.6 → 2026.11.7
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/README.md +100 -52
- package/hel_dist/css/chunk-ad8df0e6.e2ca7fbd.css +1 -0
- package/hel_dist/hel-meta.json +23 -23
- package/hel_dist/index.html +1 -1
- package/hel_dist/js/{app~493df0b3.39d7ea1f.js → app~493df0b3.677583d3.js} +3 -3
- package/hel_dist/js/{app~493df0b3.39d7ea1f.js.map → app~493df0b3.677583d3.js.map} +1 -1
- package/hel_dist/js/chunk-ad8df0e6.39491564.js +2 -0
- package/hel_dist/js/chunk-ad8df0e6.39491564.js.map +1 -0
- package/package.json +5 -1
- package/src/components/BirdSvg/index.vue +101 -0
- package/src/components/BirdSvg/source/README.md +17 -0
- package/src/components/BirdSvg/source/index.html +65 -0
- package/src/components/BirdSvg/source/style.css +284 -0
- package/src/components/BirdSvg/style.css +194 -0
- package/src/components/Butterflies3d/index.vue +245 -245
- package/src/components/Butterflies3d/source/README.md +17 -17
- package/src/components/Butterflies3d/style.css +295 -295
- package/src/components/CatFace/index.vue +128 -0
- package/src/components/CatFace/source/README.md +19 -0
- package/src/components/CatFace/source/cat.less +374 -0
- package/src/components/CatFace/source/index.html +92 -0
- package/src/components/CatFace/style.css +394 -0
- package/src/components/FrogExpressions/index.vue +94 -0
- package/src/components/FrogExpressions/source/README.md +17 -0
- package/src/components/FrogExpressions/source/demo.css +45 -0
- package/src/components/FrogExpressions/source/frog.html +375 -0
- package/src/components/FrogExpressions/source/style.css +1555 -0
- package/src/components/FrogExpressions/style.css +1109 -0
- package/src/components/WhaleFollow/index.vue +276 -0
- package/src/components/WhaleFollow/source/README.md +19 -0
- package/src/components/WhaleFollow/source/README.txt +4 -0
- package/src/components/WhaleFollow/source/index.html +29 -0
- package/src/components/WhaleFollow/source/index.js +106 -0
- package/src/components/WhaleFollow/source/license.txt +9 -0
- package/src/components/WhaleFollow/source/style.css +2 -0
- package/src/components/WhaleFollow/style.css +36 -0
- package/src/components/WhaleFollow/whaleData.js +277 -0
- package/src/components/index.js +8 -0
- package/src/entrance/libTypes.ts +12 -0
- package/hel_dist/css/chunk-f032efe6.332a9b03.css +0 -1
- package/hel_dist/js/chunk-f032efe6.d73e0465.js +0 -2
- package/hel_dist/js/chunk-f032efe6.d73e0465.js.map +0 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="stage"
|
|
4
|
+
class="whale-follow"
|
|
5
|
+
:class="{ 'is-paused': paused }"
|
|
6
|
+
role="img"
|
|
7
|
+
aria-label="一只黑白鲸鱼跟随鼠标游动"
|
|
8
|
+
></div>
|
|
9
|
+
</template>
|
|
10
|
+
|
|
11
|
+
<script>
|
|
12
|
+
/**
|
|
13
|
+
* 鲸鱼跟随鼠标(Vue 2 组件)
|
|
14
|
+
*
|
|
15
|
+
* 抽取自 https://github.com/luo0412/night-demo-codepen-gulp-2019 的
|
|
16
|
+
* gulp3-jquery-melt-ie8-mpa/_melt/ch2-effects/03-animal/whale-mouse-follow:
|
|
17
|
+
* 原始页面见 source/index.html,鲸鱼切片与渐变定义抽取到 ./whaleData.js,
|
|
18
|
+
* 原作者 Diego Leme(MIT,见 source/license.txt)。
|
|
19
|
+
*
|
|
20
|
+
* 原实现每帧把整段 SVG 字符串写回 innerHTML,并且用 setTimeout 给每片切片
|
|
21
|
+
* 制造 z 轴延迟;这里改成:
|
|
22
|
+
* - 只在 mounted 时构建一次 SVG,之后只更新每片 <g> 的 transform
|
|
23
|
+
* - 用鼠标位置历史 + 每片切片的 z*15ms 延迟取目标点,复刻原来的拖尾效果
|
|
24
|
+
* - 用 requestAnimationFrame 节流到 fps(默认 30),销毁时自动停止
|
|
25
|
+
* - 用 viewBox 1200x800 + 指针坐标映射,任意尺寸容器内鲸鱼都完整可见
|
|
26
|
+
*
|
|
27
|
+
* 对外:props = paused / ease / maxSpeed / fps
|
|
28
|
+
* methods = reset()(把鲸鱼放回容器中央)
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { whaleDefs, whaleParts } from './whaleData';
|
|
32
|
+
|
|
33
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
34
|
+
const DESIGN_WIDTH = 1200;
|
|
35
|
+
const DESIGN_HEIGHT = 800;
|
|
36
|
+
const PART_SCALE = 0.05;
|
|
37
|
+
const Z_DELAY = 15;
|
|
38
|
+
const MAX_Z = 43;
|
|
39
|
+
const MAX_DELAY = MAX_Z * Z_DELAY;
|
|
40
|
+
|
|
41
|
+
function clamp(value, min, max) {
|
|
42
|
+
return Math.min(max, Math.max(min, value));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
name: 'WhaleFollow',
|
|
47
|
+
props: {
|
|
48
|
+
// 暂停跟随(鲸鱼停在当前位置)
|
|
49
|
+
paused: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
// 缓动系数:越大越慢,源实现为 6
|
|
54
|
+
ease: {
|
|
55
|
+
type: Number,
|
|
56
|
+
default: 6
|
|
57
|
+
},
|
|
58
|
+
// 每帧每轴最大位移,源实现为 150
|
|
59
|
+
maxSpeed: {
|
|
60
|
+
type: Number,
|
|
61
|
+
default: 150
|
|
62
|
+
},
|
|
63
|
+
// 帧率,源实现为 30
|
|
64
|
+
fps: {
|
|
65
|
+
type: Number,
|
|
66
|
+
default: 30
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
computed: {
|
|
70
|
+
safeEase() {
|
|
71
|
+
const ease = Number(this.ease);
|
|
72
|
+
if (!Number.isFinite(ease) || ease <= 0) return 6;
|
|
73
|
+
return clamp(ease, 1, 30);
|
|
74
|
+
},
|
|
75
|
+
safeMaxSpeed() {
|
|
76
|
+
const maxSpeed = Number(this.maxSpeed);
|
|
77
|
+
if (!Number.isFinite(maxSpeed) || maxSpeed <= 0) return 150;
|
|
78
|
+
return clamp(maxSpeed, 10, 1000);
|
|
79
|
+
},
|
|
80
|
+
safeFps() {
|
|
81
|
+
const fps = Number(this.fps);
|
|
82
|
+
if (!Number.isFinite(fps) || fps <= 0) return 30;
|
|
83
|
+
return clamp(fps, 1, 60);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
mounted() {
|
|
87
|
+
this.parts = whaleParts.map((part) => ({
|
|
88
|
+
z: part.z,
|
|
89
|
+
x: DESIGN_WIDTH / 2,
|
|
90
|
+
y: DESIGN_HEIGHT / 2
|
|
91
|
+
}));
|
|
92
|
+
this.pointer = { x: DESIGN_WIDTH / 2, y: DESIGN_HEIGHT / 2 };
|
|
93
|
+
this.history = [];
|
|
94
|
+
this.lastFrame = 0;
|
|
95
|
+
this.raf = null;
|
|
96
|
+
this.partEls = null;
|
|
97
|
+
|
|
98
|
+
this.buildSvg();
|
|
99
|
+
this.bindEvents();
|
|
100
|
+
this.reset();
|
|
101
|
+
this.startLoop();
|
|
102
|
+
},
|
|
103
|
+
beforeDestroy() {
|
|
104
|
+
this.stopLoop();
|
|
105
|
+
this.unbindEvents();
|
|
106
|
+
if (this.partEls) {
|
|
107
|
+
this.partEls = null;
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
methods: {
|
|
111
|
+
buildSvg() {
|
|
112
|
+
const partsMarkup = whaleParts
|
|
113
|
+
.map((part, index) => {
|
|
114
|
+
const transform =
|
|
115
|
+
'matrix(' +
|
|
116
|
+
PART_SCALE +
|
|
117
|
+
' 0 0 ' +
|
|
118
|
+
PART_SCALE +
|
|
119
|
+
' ' +
|
|
120
|
+
DESIGN_WIDTH / 2 +
|
|
121
|
+
' ' +
|
|
122
|
+
DESIGN_HEIGHT / 2 +
|
|
123
|
+
')';
|
|
124
|
+
return (
|
|
125
|
+
'<g data-whale-part="' +
|
|
126
|
+
index +
|
|
127
|
+
'" transform="' +
|
|
128
|
+
transform +
|
|
129
|
+
'">' +
|
|
130
|
+
part.data +
|
|
131
|
+
'</g>'
|
|
132
|
+
);
|
|
133
|
+
})
|
|
134
|
+
.join('');
|
|
135
|
+
|
|
136
|
+
const markup =
|
|
137
|
+
'<svg xmlns="' +
|
|
138
|
+
SVG_NS +
|
|
139
|
+
'" class="whale-follow__svg" viewBox="0 0 ' +
|
|
140
|
+
DESIGN_WIDTH +
|
|
141
|
+
' ' +
|
|
142
|
+
DESIGN_HEIGHT +
|
|
143
|
+
'" preserveAspectRatio="xMidYMid meet" aria-hidden="true" focusable="false">' +
|
|
144
|
+
whaleDefs +
|
|
145
|
+
partsMarkup +
|
|
146
|
+
'</svg>';
|
|
147
|
+
|
|
148
|
+
const doc = new DOMParser().parseFromString(markup, 'image/svg+xml');
|
|
149
|
+
if (doc.querySelector('parsererror')) {
|
|
150
|
+
console.error('[WhaleFollow] SVG 解析失败');
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const svg = document.importNode(doc.documentElement, true);
|
|
155
|
+
this.$refs.stage.appendChild(svg);
|
|
156
|
+
this.partEls = svg.querySelectorAll('g[data-whale-part]');
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
bindEvents() {
|
|
160
|
+
this.onPointerMove = (event) => {
|
|
161
|
+
if (event.type === 'touchmove' && event.cancelable) event.preventDefault();
|
|
162
|
+
const point = this.toDesignPoint(event);
|
|
163
|
+
if (!point) return;
|
|
164
|
+
this.pointer.x = point.x;
|
|
165
|
+
this.pointer.y = point.y;
|
|
166
|
+
};
|
|
167
|
+
this.$el.addEventListener('mousemove', this.onPointerMove);
|
|
168
|
+
this.$el.addEventListener('touchmove', this.onPointerMove, { passive: false });
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
unbindEvents() {
|
|
172
|
+
this.$el.removeEventListener('mousemove', this.onPointerMove);
|
|
173
|
+
this.$el.removeEventListener('touchmove', this.onPointerMove);
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
// 把鼠标 / 触摸坐标映射到 1200x800 的 SVG 设计坐标(考虑 viewBox 留白)
|
|
177
|
+
toDesignPoint(event) {
|
|
178
|
+
const rect = this.$el.getBoundingClientRect();
|
|
179
|
+
if (!rect.width || !rect.height) return null;
|
|
180
|
+
const point = event.touches && event.touches.length ? event.touches[0] : event;
|
|
181
|
+
const scale = Math.min(rect.width / DESIGN_WIDTH, rect.height / DESIGN_HEIGHT);
|
|
182
|
+
if (!scale) return null;
|
|
183
|
+
const offsetX = (rect.width - DESIGN_WIDTH * scale) / 2;
|
|
184
|
+
const offsetY = (rect.height - DESIGN_HEIGHT * scale) / 2;
|
|
185
|
+
return {
|
|
186
|
+
x: clamp((point.clientX - rect.left - offsetX) / scale, 0, DESIGN_WIDTH),
|
|
187
|
+
y: clamp((point.clientY - rect.top - offsetY) / scale, 0, DESIGN_HEIGHT)
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
startLoop() {
|
|
192
|
+
if (this.raf) return;
|
|
193
|
+
const tick = (time) => {
|
|
194
|
+
this.raf = requestAnimationFrame(tick);
|
|
195
|
+
if (this.paused) return;
|
|
196
|
+
const frameMs = 1000 / this.safeFps;
|
|
197
|
+
if (time - this.lastFrame < frameMs) return;
|
|
198
|
+
this.lastFrame = time;
|
|
199
|
+
this.update(time);
|
|
200
|
+
};
|
|
201
|
+
this.raf = requestAnimationFrame(tick);
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
stopLoop() {
|
|
205
|
+
if (this.raf) {
|
|
206
|
+
cancelAnimationFrame(this.raf);
|
|
207
|
+
this.raf = null;
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
update(now) {
|
|
212
|
+
this.history.push({ t: now, x: this.pointer.x, y: this.pointer.y });
|
|
213
|
+
const keepFrom = now - MAX_DELAY - 1000 / this.safeFps;
|
|
214
|
+
while (this.history.length > 2 && this.history[0].t < keepFrom) {
|
|
215
|
+
this.history.shift();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (let index = 0; index < this.parts.length; index += 1) {
|
|
219
|
+
const part = this.parts[index];
|
|
220
|
+
const targetTime = now - part.z * Z_DELAY;
|
|
221
|
+
let target = this.history[0];
|
|
222
|
+
for (let i = this.history.length - 1; i >= 0; i -= 1) {
|
|
223
|
+
if (this.history[i].t <= targetTime) {
|
|
224
|
+
target = this.history[i];
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const maxSpeed = this.safeMaxSpeed;
|
|
229
|
+
part.x += clamp(target.x - part.x, -maxSpeed, maxSpeed) / this.safeEase;
|
|
230
|
+
part.y += clamp(target.y - part.y, -maxSpeed, maxSpeed) / this.safeEase;
|
|
231
|
+
this.applyPartTransform(index);
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
applyPartTransform(index) {
|
|
236
|
+
if (!this.partEls || !this.partEls[index]) return;
|
|
237
|
+
const part = this.parts[index];
|
|
238
|
+
this.partEls[index].setAttribute(
|
|
239
|
+
'transform',
|
|
240
|
+
'matrix(' +
|
|
241
|
+
PART_SCALE +
|
|
242
|
+
' 0 0 ' +
|
|
243
|
+
PART_SCALE +
|
|
244
|
+
' ' +
|
|
245
|
+
part.x.toFixed(2) +
|
|
246
|
+
' ' +
|
|
247
|
+
part.y.toFixed(2) +
|
|
248
|
+
')'
|
|
249
|
+
);
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
updateTransforms() {
|
|
253
|
+
for (let index = 0; index < this.parts.length; index += 1) {
|
|
254
|
+
this.applyPartTransform(index);
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
reset() {
|
|
259
|
+
const now = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
260
|
+
const center = { x: DESIGN_WIDTH / 2, y: DESIGN_HEIGHT / 2 };
|
|
261
|
+
this.pointer = { x: center.x, y: center.y };
|
|
262
|
+
this.history = [
|
|
263
|
+
{ t: now - MAX_DELAY, x: center.x, y: center.y },
|
|
264
|
+
{ t: now, x: center.x, y: center.y }
|
|
265
|
+
];
|
|
266
|
+
this.parts.forEach((part) => {
|
|
267
|
+
part.x = center.x;
|
|
268
|
+
part.y = center.y;
|
|
269
|
+
});
|
|
270
|
+
this.updateTransforms();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
</script>
|
|
275
|
+
|
|
276
|
+
<style scoped src="./style.css"></style>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# 原始来源
|
|
2
|
+
|
|
3
|
+
- CodePen:<https://codepen.io/diegoleme/pen/rIokB>(Whale | SVG & JS,by Diego Leme)
|
|
4
|
+
- 仓库文件:`gulp3-jquery-melt-ie8-mpa/_melt/ch2-effects/03-animal/whale-mouse-follow/`
|
|
5
|
+
- 本目录原样保留 `index.html`、`style.css`、`index.js`、`license.txt`、`README.txt`。
|
|
6
|
+
原作者采用 **MIT** 许可(见 `license.txt`),再分发时请保留该版权声明。
|
|
7
|
+
|
|
8
|
+
改写为 Vue 2 组件(`../index.vue`)时的处理:
|
|
9
|
+
|
|
10
|
+
- 原 `index.js` 里的 `defs`(渐变定义)与 `parts`(44 片鲸鱼 SVG 切片数据)抽取到
|
|
11
|
+
`../whaleData.js`,只作为静态数据导入。
|
|
12
|
+
- 原实现每帧把整段 SVG 字符串写回 `element.innerHTML`,并给每片切片
|
|
13
|
+
`setTimeout(..., z * 15ms)` 制造延迟;组件改为:
|
|
14
|
+
- 只在 `mounted` 时构建一次 SVG,之后只更新每片 `<g>` 的 `transform`;
|
|
15
|
+
- 用最近约 650ms 的鼠标位置历史模拟 `z * 15ms` 的延迟,保留原来的拖尾;
|
|
16
|
+
- `requestAnimationFrame` + `fps` 节流,`beforeDestroy` 自动停止。
|
|
17
|
+
- 原页面用视口像素坐标、鲸鱼大小固定;组件改为 1200×800 的 viewBox + 指针坐标映射,
|
|
18
|
+
鲸鱼在任意尺寸容器内都完整可见。
|
|
19
|
+
- 新增 `paused` / `ease` / `maxSpeed` / `fps` props 与 `reset()` 方法。
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
|
|
8
|
+
<title>Whale | SVG & JS - CodePen</title>
|
|
9
|
+
|
|
10
|
+
<link href="https://cdn.bootcss.com/normalize/7.0.0/normalize.min.css" rel="stylesheet">
|
|
11
|
+
|
|
12
|
+
<link rel="stylesheet" href="css/style.css" media="screen"/>
|
|
13
|
+
|
|
14
|
+
</head>
|
|
15
|
+
|
|
16
|
+
<body>
|
|
17
|
+
<div style="text-align:center;clear:both">
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
</div>
|
|
21
|
+
<div id="whale"></div>
|
|
22
|
+
|
|
23
|
+
<!--<script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script>-->
|
|
24
|
+
<script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
|
|
25
|
+
<script src="js/index.js"></script>
|
|
26
|
+
|
|
27
|
+
</body>
|
|
28
|
+
|
|
29
|
+
</html>
|