代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
width: 100vw;
height: 100vh;
transform-style: preserve-3d;
perspective: 500px;
}
#card {
--per: 30%;
width: 300px;
height: 400px;
position: relative;
background: url('EX1_287.png');
background-size: cover;
/* box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.5); */
}
#card::after {
content: "";
position: absolute;
margin: auto;
margin-top: 20px;
width: 260px;
height: 370px;
display: none;
inset: 0;
background: url("1.gif");
mix-blend-mode: color-dodge;
}
#card::before {
margin: auto;
margin-top: 20px;
width: 260px;
height: 360px;
content:'';
background:
linear-gradient(
115deg,
transparent 0%,
rgba(243, 252, 2, 0.288) var(--per),
rgba(0, 0, 0, .5) calc(var(--per) + 25%),
rgba(243, 252, 2, 0.288) calc(var(--per) + 50%),
transparent 100%
);
position: absolute;
inset: 0;
mix-blend-mode: color-dodge;
}
#card:hover::after,
#card:hover::before {
display: block;
}
</style>
</head>
<body>
<div id="card"></div>
<script>
const card = document.getElementById("card");
card.onmousemove = function (e) {
let box = card.getBoundingClientRect();
let calcY = (e.clientX - box.x - (box.width / 2)) / -7;
let calcX = (e.clientY - box.y - (box.height / 2)) / 7;
card.style.transform = "rotateY(" + calcY + "deg)" + "rotateX(" + calcX + "deg) ";
const percentage = parseInt((e.clientX - box.x) / box.width * 1000) / 10;
card.style.setProperty("--per", `${percentage}%`);
// card.style.boxShadow = `${-calcX}px ${-calcY}px 20px rgba(0, 0, 0, 0.5)`;
}
card.addEventListener('mouseleave', (e) => {
window.requestAnimationFrame(function () {
card.style.transform = "rotateX(0) rotateY(0)";
});
});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。