张延森 2 år sedan
förälder
incheckning
1ec1978285
6 ändrade filer med 128 tillägg och 11 borttagningar
  1. 1
    1
      src/App.vue
  2. Binär
      src/assets/cloud-texture.png
  3. 1
    1
      src/components/Fog.vue
  4. 35
    9
      src/components/Loader.vue
  5. 87
    0
      src/components/Mask.vue
  6. 4
    0
      vite.config.js

+ 1
- 1
src/App.vue Visa fil

@@ -24,7 +24,7 @@ onMounted(() => {
24 24
 <template>
25 25
   <Loader :loading="loading" :percent="percent" />
26 26
   <ScrollDown />
27
-  <Image v-for="(res, inx) in resources" :key="res.image" :resource="res" :show-fog="inx === 0"></Image>
27
+  <Image v-for="(res, inx) in resources" :key="res.image" :resource="res"></Image>
28 28
 </template>
29 29
 
30 30
 <style scoped>

Binär
src/assets/cloud-texture.png Visa fil


+ 1
- 1
src/components/Fog.vue Visa fil

@@ -47,7 +47,7 @@
47 47
       opacity: 0;
48 48
     }
49 49
     50% {
50
-      opacity: 0.8;
50
+      opacity: 1;
51 51
     }
52 52
     100%{
53 53
       transform: translate(60%, -40%);

+ 35
- 9
src/components/Loader.vue Visa fil

@@ -1,5 +1,11 @@
1 1
 <template>
2
-  <div class="loader-wrapper" :class="{ loaded: !loading }">
2
+  <div 
3
+    class="loader-wrapper"
4
+    :class="{ loaded: !loading }"
5
+    :style="visibleStyle"
6
+    @touchmove.prevent
7
+    @mousewheel.prevent
8
+  >
3 9
     <div class="loader">
4 10
       <p class="tip">{{tip}}</p>
5 11
       <p class="percent">{{percent}}%</p>
@@ -7,13 +13,15 @@
7 13
         <div :style="progressStyle"></div>
8 14
       </p>
9 15
     </div>
10
-    <div class="loader-section section-top"></div>
11
-    <div class="loader-section section-bottom"></div>    
16
+    <!-- <div class="loader-section section-top"></div>
17
+    <div class="loader-section section-bottom"></div>     -->
18
+    <MaskVue ref="maskRef" @end="onEnd"/>
12 19
   </div>
13 20
 </template>
14 21
 
15 22
 <script setup>
16
-import { computed } from "vue"
23
+import { computed, onMounted, ref, watch } from "vue"
24
+import MaskVue from "./Mask.vue";
17 25
 
18 26
 const props = defineProps({
19 27
   tip: {
@@ -27,7 +35,24 @@ const props = defineProps({
27 35
   loading: Boolean
28 36
 })
29 37
 
30
-const progressStyle = computed(() => ({ width: `${props.percent}%` }))
38
+const elRef = ref();
39
+const maskRef = ref();
40
+const progressStyle = computed(() => ({ width: `${props.percent}%` }));
41
+const visibleStyle = ref({  })
42
+const onEnd = () => {
43
+  visibleStyle.value = { visibility: 'hidden' }
44
+}
45
+
46
+const onTouchMove = (e) => {
47
+  // 禁止滚动
48
+  e.preventDefault();
49
+}
50
+
51
+watch(() => props.loading, (newVal, oldVal) => {
52
+  if (oldVal && !newVal) {
53
+    maskRef.value.start();
54
+  }
55
+})
31 56
 
32 57
 </script>
33 58
 
@@ -44,8 +69,9 @@ const progressStyle = computed(() => ({ width: `${props.percent}%` }))
44 69
   left: 0;
45 70
   width: 100%;
46 71
   height: 100%;
47
-  z-index: 10;
72
+  z-index: 100;
48 73
   overflow: hidden;
74
+  background: @bg-color;
49 75
 
50 76
   .loader {
51 77
     display: block;
@@ -90,9 +116,9 @@ const progressStyle = computed(() => ({ width: `${props.percent}%` }))
90 116
   }
91 117
 
92 118
   &.loaded {
93
-    visibility: hidden;
94
-    transform: translateX(-100%);
95
-    transition: all 0.3s 1s ease-out;
119
+    // visibility: hidden;
120
+    // transform: translateX(-100%);
121
+    // transition: all 0.3s 1s ease-out;
96 122
 
97 123
     .loader {
98 124
       opacity: 0;

+ 87
- 0
src/components/Mask.vue Visa fil

@@ -0,0 +1,87 @@
1
+<template>
2
+  <canvas ref="cvsRef"></canvas>
3
+</template>
4
+
5
+<script setup>
6
+  import { onMounted, ref } from 'vue';
7
+  import indexImage from '@/assets/images/1.jpg';
8
+  import maskImage from '@/assets/cloud-texture.png';
9
+
10
+  // const props = defineProps({
11
+  //   img: {
12
+  //     type: Object,
13
+  //     default: null,
14
+  //   }
15
+  // })
16
+
17
+  const emit = defineEmits(['end']);
18
+
19
+  const cvsRef = ref();
20
+  const ctxRef = ref();
21
+  const img = new Image();
22
+  img.src = indexImage;
23
+  img.onload = function() {
24
+    const canv = cvsRef.value;
25
+    canv.width = img.naturalWidth;
26
+    canv.height = img.naturalHeight;
27
+  }
28
+  const imgMask = new Image();
29
+  imgMask.src = maskImage;
30
+
31
+  let i = 0;
32
+  let animationId = 0;
33
+
34
+  const xStart = 60;
35
+  const yStart = 90;
36
+  const speed = 20;
37
+  const draw = () => {
38
+    i += speed;
39
+    const canv = cvsRef.value;
40
+    const maskX = (canv.width - (xStart + i)) / 2;
41
+    const maskY = (canv.height - (yStart + i)) / 2;
42
+    const maskWidth = xStart + i;
43
+    const maskHeight = yStart + i;
44
+    
45
+    const ctx = ctxRef.value;
46
+    ctx.clearRect(0, 0, canv.width, canv.height);
47
+    ctx.globalCompositeOperation = "source-over";
48
+    
49
+    ctx.drawImage(imgMask, maskX, maskY, maskWidth, maskHeight);
50
+    
51
+    ctx.globalCompositeOperation = "source-in";
52
+    ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight);    
53
+    animationId = window.requestAnimationFrame(draw);
54
+    
55
+    const { clientWidth, clientHeight } = document.body;
56
+    if ((maskWidth - clientWidth + maskX) > img.naturalWidth && (maskHeight - clientHeight + maskY) > img.naturalHeight) {
57
+      // 动画就结束
58
+      window.cancelAnimationFrame(animationId);
59
+      emit('end');
60
+    }
61
+  }
62
+
63
+  const start = () => {
64
+    i = 0;
65
+    draw();
66
+  }
67
+
68
+  onMounted(() => {
69
+    ctxRef.value = cvsRef.value.getContext("2d");
70
+  })
71
+
72
+  defineExpose({
73
+    start,
74
+  })
75
+
76
+</script>
77
+
78
+<style lang="less" scoped>
79
+canvas {
80
+  position: fixed;
81
+  width: 100vw;
82
+  height: 100vh;
83
+  left: 0;
84
+  top: 0;
85
+  z-index: 20;
86
+}
87
+</style>

+ 4
- 0
vite.config.js Visa fil

@@ -4,6 +4,10 @@ import vue from '@vitejs/plugin-vue'
4 4
 
5 5
 // https://vitejs.dev/config/
6 6
 export default defineConfig({
7
+  base: '',
8
+  server:{
9
+    host: '0.0.0.0',
10
+  },
7 11
   plugins: [vue()],
8 12
   resolve:{
9 13
     alias:{