hookehuyr

refactor(animation.vue): 调整布局和样式以提升响应性和可读性

将按钮位置固定在右上角,优化SVG容器尺寸以适应不同屏幕。调整节点大小和间距,提升用户体验。更新CSS单位以增强响应性。
1 <!-- 1 <!--
2 * @Date: 2025-03-28 09:23:04 2 * @Date: 2025-03-28 09:23:04
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-03-28 13:26:37 4 + * @LastEditTime: 2025-03-28 13:44:59
5 * @FilePath: /mlaj/src/views/animation.vue 5 * @FilePath: /mlaj/src/views/animation.vue
6 * @Description: 贝塞尔曲线动画路径组件 6 * @Description: 贝塞尔曲线动画路径组件
7 * 7 *
...@@ -14,8 +14,10 @@ ...@@ -14,8 +14,10 @@
14 --> 14 -->
15 <template> 15 <template>
16 <div class="animation-container"> 16 <div class="animation-container">
17 - <button class="next-button" @click="nextStep" :disabled="activeNodeIndex >= points.length - 1">下一步</button> 17 + <div style="position: fixed; top: 0; right: 0;">
18 - <svg width="1000" height="1000" viewBox="0 0 1000 1000"> 18 + <button class="next-button" @click="nextStep" :disabled="activeNodeIndex >= points.length - 1">下一步</button>
19 + </div>
20 + <svg width="100%" height="100%" viewBox="0 0 1000 1000" class="animation-svg">
19 <!-- 定义箭头标记 --> 21 <!-- 定义箭头标记 -->
20 <defs> 22 <defs>
21 <marker 23 <marker
...@@ -74,7 +76,7 @@ ...@@ -74,7 +76,7 @@
74 <circle 76 <circle
75 :cx="point.x" 77 :cx="point.x"
76 :cy="point.y" 78 :cy="point.y"
77 - r="6" 79 + r="12"
78 :class="['node', { 'node-active': activeNodeIndex >= index - 1 }]" 80 :class="['node', { 'node-active': activeNodeIndex >= index - 1 }]"
79 @click="activateNode(index)" 81 @click="activateNode(index)"
80 /> 82 />
...@@ -89,11 +91,11 @@ import { ref, computed } from 'vue'; ...@@ -89,11 +91,11 @@ import { ref, computed } from 'vue';
89 // 定义节点坐标数组,每个节点包含x和y坐标 91 // 定义节点坐标数组,每个节点包含x和y坐标
90 // 这些点将用于生成贝塞尔曲线的路径 92 // 这些点将用于生成贝塞尔曲线的路径
91 const points = ref([ 93 const points = ref([
92 - { x: 250, y: 50 }, 94 + { x: 700, y: 50 },
93 - { x: 10, y: 250 }, 95 + { x: 300, y: 300 },
94 - { x: 400, y: 500 }, 96 + { x: 700, y: 600 },
95 - { x: 50, y: 700 }, 97 + { x: 300, y: 800 },
96 - { x: 400, y: 950 } 98 + { x: 700, y: 1000 }
97 ]); 99 ]);
98 100
99 // 当前激活的节点索引,初始值为-1表示没有节点被激活 101 // 当前激活的节点索引,初始值为-1表示没有节点被激活
...@@ -132,7 +134,7 @@ const calculatePathSegment = (startPoint, endPoint) => { ...@@ -132,7 +134,7 @@ const calculatePathSegment = (startPoint, endPoint) => {
132 134
133 // 设置节点间的偏移距离(可以根据需要调整) 135 // 设置节点间的偏移距离(可以根据需要调整)
134 const offset = 0; 136 const offset = 0;
135 - const verticalOffset = -20; // 添加垂直偏移量参数 137 + const verticalOffset = -30; // 添加垂直偏移量参数
136 138
137 // 计算单位向量 139 // 计算单位向量
138 const unitX = dx / distance; 140 const unitX = dx / distance;
...@@ -207,16 +209,42 @@ const nextStep = () => { ...@@ -207,16 +209,42 @@ const nextStep = () => {
207 <style scoped> 209 <style scoped>
208 .animation-container { 210 .animation-container {
209 display: flex; 211 display: flex;
212 + flex-direction: column;
210 justify-content: center; 213 justify-content: center;
211 align-items: center; 214 align-items: center;
212 min-height: 100vh; 215 min-height: 100vh;
213 background: #f5f5f5; 216 background: #f5f5f5;
217 + padding: 1.25rem;
218 + box-sizing: border-box;
214 } 219 }
215 220
221 +.animation-svg {
222 + max-width: 100%;
223 + max-height: 100vh;
224 + margin: 0 auto;
225 +}
226 +
227 +@media screen and (max-width: 768px) {
228 + .animation-container {
229 + padding: 0.9375rem;
230 + }
231 +
232 + .animation-svg {
233 + height: 80vh;
234 + }
235 +
236 + .next-button {
237 + padding: 0.5rem 1rem;
238 + font-size: 1rem;
239 + }
240 +
241 + .node {
242 + }
243 +}
216 .node { 244 .node {
217 fill: white; 245 fill: white;
218 stroke: #ccc; 246 stroke: #ccc;
219 - stroke-width: 2; 247 + stroke-width: 0.125rem;
220 cursor: pointer; 248 cursor: pointer;
221 transition: all 0.3s ease; 249 transition: all 0.3s ease;
222 } 250 }
...@@ -236,19 +264,19 @@ const nextStep = () => { ...@@ -236,19 +264,19 @@ const nextStep = () => {
236 264
237 @keyframes dash { 265 @keyframes dash {
238 to { 266 to {
239 - stroke-dashoffset: -20; 267 + stroke-dashoffset: -1.25rem;
240 } 268 }
241 } 269 }
242 270
243 .next-button { 271 .next-button {
244 position: absolute; 272 position: absolute;
245 - top: 20px; 273 + top: 1.25rem;
246 - right: 20px; 274 + right: 1.25rem;
247 - padding: 8px 16px; 275 + padding: 0.5rem 1rem;
248 background-color: #4CAF50; 276 background-color: #4CAF50;
249 color: white; 277 color: white;
250 border: none; 278 border: none;
251 - border-radius: 4px; 279 + border-radius: 0.25rem;
252 cursor: pointer; 280 cursor: pointer;
253 transition: all 0.3s ease; 281 transition: all 0.3s ease;
254 } 282 }
......