HTML5+CSS3小實例:翻書動畫

實例:翻書動畫
技術(shù)棧:HTML+CSS
效果:

源碼:
【html】

<!DOCTYPE html>
<html>
 
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
 
    <title>純CSS實現(xiàn)翻書動畫</title>
    <link rel="stylesheet" href="../css/84.css">
</head>
 
<body>
    <div class="book">
        <div class="cover">
            <span>葵花寶典</span>
        </div>
        <div class="content">
            <p>欲練此功</p>
            <p>必先自宮</p>
        </div>
    </div>
</body>
 
</html>

【css】

*{
    /* 初始化 */
    margin: 0;
    padding: 0;
}
body{
    /* 100%窗口高度 */
    height: 100vh;
    /* 彈性布局 水平+垂直居中 */
    display: flex;
    justify-content: center;
    align-items: center;
    background: #dfb88e;
}
.book{
    width: 300px;
    height: 400px;
    background-color: #fff;
    /* 開啟3D效果 */
    transform-style: preserve-3d;
    /* 設置視距 */
    perspective: 2000px;
    /* 陰影 */
    box-shadow: inset 300px 0 30px rgba(0,0,0,0.2),
    0 10px 100px rgba(0,0,0,0.3);
    /* 動畫過渡 */
    transition: 1s;
}
/* 鼠標移入,陰影變化+旋轉(zhuǎn) */
.book:hover{
    transform: rotate(-10deg);
    box-shadow: inset 20px 0 30px rgba(0,0,0,0.2),
    0 10px 100px rgba(0,0,0,0.3);
}
.book::before{
    content: "";
    position: absolute;
    left: 0;
    top: -5px;
    width: 100%;
    height: 5px;
    background-color: #0d2a50;
    transform-origin: bottom;
    transform: skewX(-45deg);
}
.book::after{
    content: "";
    position: absolute;
    top: 0;
    right: -5px;
    width: 5px;
    height: 100%;
    background-color: #3d5a83;
    transform-origin: left;
    transform: skewY(-45deg);
}
/* 封面 */
.book .cover{
    width: 100%;
    height: 100%;
    background-color: #2A3F5C;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 相對定位 */
    position: relative;
    /* 設置旋轉(zhuǎn)元素的基點位置 */
    transform-origin: left;
    transition: 1s;
}
.book .cover span{
    /* 絕對定位 */
    position: absolute;
    right: 30px;
    top: 30px;
    background-color: #fff;
    font-size: 40px;
    font-family: "隸書";
    /* 豎向文本 */
    writing-mode: vertical-lr;
    padding: 10px 5px 5px 5px;
    /* 字間距 */
    letter-spacing: 5px;
}
.book:hover .cover{
    transform: rotateY(-135deg);
}
.book .content{
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
    font-size: 40px;
    font-family: "隸書";
    line-height: 50px;
    letter-spacing: 5px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容