效果
代码一
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
#photo{
width: 100%;
height: 100%;
background-image: url("img/11.png");
background-repeat: no-repeat;
background-size: cover;
}
#div1{
width: 100%;
height: 100%;
position: absolute;
background: radial-gradient(circle at var(--xx) var(--yy),transparent,#000 10%);
}
</style>
</head>
<body>
<div id="div1"></div>
<div id="photo"></div>
<script>
var pos = document.documentElement;
pos.addEventListener("mousemove",function (e) {
pos.style.setProperty("--xx",e.clientX+"px");
pos.style.setProperty("--yy",e.clientY+"px");
});
</script>
</body>
</html>
代码二
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
body{
background: black;
}
#photo{
width: 100%;
height: 100%;
background-image: url("img/11.png");
background-repeat: no-repeat;
background-size: cover;
clip-path: circle(10% at var(--xx) var(--yy));
}
</style>
</head>
<body>
<div id="photo"></div>
<script>
var pos = document.documentElement;
pos.addEventListener("mousemove",function (e) {
pos.style.setProperty("--xx",e.clientX+"px");
pos.style.setProperty("--yy",e.clientY+"px");
})
</script>
</body>
</html>
代码三,升级版
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
body{
background: black;
}
#photo{
width: 100%;
height: 100%;
background-image: url("img/11.png");
background-repeat: no-repeat;
background-size: cover;
clip-path: circle(10% at var(--xx) var(--yy));
}
#photo:active{
clip-path: circle(20% at var(--xx) var(--yy));
}
</style>
</head>
<body>
<div id="photo"></div>
<script>
var pos = document.documentElement;
pos.addEventListener("mousemove",function (e) {
pos.style.setProperty("--xx",e.clientX+"px");
pos.style.setProperty("--yy",e.clientY+"px");
})
</script>
</body>
</html>