图片镂空
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
margin: 0;
height: 100vh;
display: grid;
place-content: center;
}
.prew{
display: block;
width: 800px;
}
.wrap{
position: relative;
overflow:hidden;
}
.wrap::after{
content: '';
position: absolute;
width: 100px;
height: 100px;
border-radius: 50%;
left: calc(var(--x, .5) * 100%);
top: calc(var(--y, .5) * 100%);
transform: translate(-50%,-50%);
box-shadow: 0 0 0 999vw rgba(0, 0, 0, .5); /*足够大的投影*/
}
</style>
</head>
<body>
<div class="wrap" id="img">
<img class="prew" src="https://tva1.sinaimg.cn/large/008i3skNgy1gubr2sbyqdj60xa0m6tey02.jpg">
</div>
</body>
<script>
img.addEventListener('mousemove', (ev) => {
img.style.setProperty('--x', ev.offsetX / ev.target.offsetWidth);
img.style.setProperty('--y', ev.offsetY / ev.target.offsetHeight);
})
</script>
</html>
Snipaste_2022-10-17_15-17-14.png