JSFiddle - React, Tailwind, and code Playground
by HDL52
HTML
<section>
<h2>Paragraph</h2>
<div class="glass"></div>
</section>
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
section {
position: relative;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: url(https://raw.githubusercontent.com/Hongda-OSU/PicGo-2.3.1/master/imge39twvhffwemdsipqncbwko5vayrxgd.jpg);
background-position: center;
background-attachment: fixed;
background-size: cover;
overflow: hidden;
}
section h2 {
font-size: 5em;
color: #fff;
pointer-events: none;
text-shadow: 0 10px 20px rgba(0, 0, 0, 0.5);
}
section .glass {
position: absolute;
transform: translate(-50%, -50%);
pointer-events: none;
width: 300px;
height: 200px;
box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
background: transparent;
backdrop-filter: blur(10px);
transition: 0.2s;
}
JavaScript
// https://juejin.cn/post/7313911560442462208
let glass = document.querySelector(".glass");
let mouseX = 0, mouseY = 0;
document.addEventListener("mousemove", function (e) {
mouseX = e.pageX;
mouseY = e.pageY;
});
function moveGlass() {
glass.style.left = mouseX + "px";
glass.style.top = mouseY + "px";
requestAnimationFrame(moveGlass);
}
moveGlass();