1 Star 0 Fork 0

Aran/3d卡片特效

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
floatcard.html 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
Aran 提交于 2024-06-08 14:20 . 完成卡片特效
<!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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lu0ran/3Dcard.git
git@gitee.com:lu0ran/3Dcard.git
lu0ran
3Dcard
3d卡片特效
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385