|
@@ -4,8 +4,8 @@
|
4
|
4
|
|
5
|
5
|
<script setup>
|
6
|
6
|
import { onMounted, ref } from 'vue';
|
7
|
|
- import indexImage from '@/assets/images/1.jpg';
|
8
|
|
- import maskImage from '@/assets/cloud-texture.png';
|
|
7
|
+ import indexImage from '@/assets/index.jpg';
|
|
8
|
+ import maskImage from '@/assets/mask.png';
|
9
|
9
|
|
10
|
10
|
// const props = defineProps({
|
11
|
11
|
// img: {
|
|
@@ -15,20 +15,20 @@
|
15
|
15
|
// })
|
16
|
16
|
|
17
|
17
|
const emit = defineEmits(['end']);
|
|
18
|
+ const { clientWidth, clientHeight } = document.body;
|
18
|
19
|
|
19
|
20
|
const cvsRef = ref();
|
20
|
21
|
const ctxRef = ref();
|
21
|
22
|
const img = new Image();
|
|
23
|
+ const imgHeight = ref();
|
22
|
24
|
img.src = indexImage;
|
23
|
25
|
img.onload = function() {
|
24
|
26
|
const canv = cvsRef.value;
|
25
|
27
|
|
26
|
|
- const { clientWidth, clientHeight } = document.body;
|
27
|
|
- canv.style.width = `${clientWidth}px`;
|
28
|
|
- canv.style.height = `${img.naturalHeight * clientWidth / img.naturalWidth}px`;
|
|
28
|
+ imgHeight.value = img.naturalWidth * clientHeight / clientWidth
|
29
|
29
|
|
30
|
30
|
canv.width = img.naturalWidth;
|
31
|
|
- canv.height = img.naturalHeight;
|
|
31
|
+ canv.height = imgHeight.value; // img.naturalHeight;
|
32
|
32
|
}
|
33
|
33
|
const imgMask = new Image();
|
34
|
34
|
imgMask.src = maskImage;
|
|
@@ -54,11 +54,10 @@
|
54
|
54
|
ctx.drawImage(imgMask, maskX, maskY, maskWidth, maskHeight);
|
55
|
55
|
|
56
|
56
|
ctx.globalCompositeOperation = "source-in";
|
57
|
|
- ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight);
|
|
57
|
+ ctx.drawImage(img, 0, 0, img.naturalWidth, img.naturalHeight);
|
58
|
58
|
animationId = window.requestAnimationFrame(draw);
|
59
|
59
|
|
60
|
|
- const { clientWidth, clientHeight } = document.body;
|
61
|
|
- if ((maskWidth - clientWidth + maskX) > img.naturalWidth && (maskHeight - clientHeight + maskY) > img.naturalHeight) {
|
|
60
|
+ if ((maskWidth - clientWidth + maskX) > img.naturalWidth && (maskHeight - clientHeight + maskY) > imgHeight.value) {
|
62
|
61
|
// 动画就结束
|
63
|
62
|
window.cancelAnimationFrame(animationId);
|
64
|
63
|
emit('end');
|