纯css实现翻书/打开笔记本动画效果

231 阅读1分钟

闲来无事最近每天坚持写几个css特效玩玩,不断研究不断研究,hover,perspective、box-shadow、transition、transform这些强大的css属性真是牛啤plus~越写越喜欢的感觉ing~~~~

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>翻书动画效果</title>
    <style>
        .book-box {
            position: relative;
            width: 240px;
            height: 300px;
            background-color: #eee;
            border-radius: 10px;
            box-shadow: 2px 2px 10px #000;
            perspective: 2000px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #000;
        }

        .outer {
            position: absolute;
            background-color: #ccc;
            width: 100%;
            height: 100%;
            border-radius: 20px;
            cursor: pointer;
            transition: transform 0.8s;
            transform-origin: left; 
            display: flex;
            align-items: center;
            justify-content: center;
        }
		
		/* 角度控制 */
        .book-box:hover .outer {
            transform: rotateY(-85deg);
        }

        p {
            font-size: 20px;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="book-box">
        <p>打开就可以看到我了</p>
        <div class="outer">
            <p>鼠标移入</p>
        </div>
    </div>
</body>
</html>

  • .book-box 是包含整个翻书效果的容器,设置了相对定位和透视效果。
  • .outer 是翻开的书页,设置为绝对定位,背景色和圆角效果,并且添加了过渡效果以及鼠标悬停时的翻转效果
  • 当鼠标悬停在 .book-box 上时,.outer 元素会发生一个 Y 轴旋转的动画,使其看起来像在翻页。