利用css属性clip-path来绘制图片遮罩

MDN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<template>
<img ref="img" class="img active" src="./assets/pic.jpg" alt="">
</template>

<style>
:root {
box-sizing: border-box;
}

html,
body {
all: unset
}

.app {
background-color: var(--color);

}

.img {
object-fit: cover;
width: 500px;
height: 500px;
clip-path: circle(0% at 0% 50%);
transition: 1s;
}

.img.active {
clip-path: circle(50% at 50% 50%);
}
</style>
<script setup>
import { onMounted, onUnmounted, ref } from 'vue';
const img = ref(null)
const timer = onMounted(() => {
setInterval(() => {
img.value.classList.toggle('active')
}, 1500);
})
onUnmounted(() => {
clearInterval(timer)
})
</script>