HTML5+CSS3小實(shí)例:3D旋轉(zhuǎn)木馬相冊(cè)

HTML5+CSS3做一個(gè)3D旋轉(zhuǎn)木馬相冊(cè),鼠標(biāo)懸停時(shí),停止旋轉(zhuǎn),移開繼續(xù)旋轉(zhuǎn),大家把圖片替換成自己的即可。

效果:

源碼:

<!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>3D旋轉(zhuǎn)木馬相冊(cè)</title>
    <link rel="stylesheet" href="../css/27.css">
</head>

<body>
    <section>
        <div><img src="../images/op/1.jpg" alt=""></div>
        <div><img src="../images/op/2.jpg" alt=""></div>
        <div><img src="../images/op/3.jpg" alt=""></div>
        <div><img src="../images/op/4.jpg" alt=""></div>
        <div><img src="../images/op/5.jpg" alt=""></div>
        <div><img src="../images/op/6.jpg" alt=""></div>
        <div><img src="../images/op/7.jpg" alt=""></div>
        <div><img src="../images/op/8.jpg" alt=""></div>
    </section>
</body>

</html>
*{
    /* 初始化 取消頁面的內(nèi)外邊距 */
    margin: 0;
    padding: 0;
}
body{
    /* 彈性布局 水平、垂直居中 */
    display: flex;
    justify-content: center;
    align-items: center;
    /* 100%窗口高度 */
    height: 100vh;
    background-color: #000;
    /* 視距 讓元素看起來更有3D效果 */
    perspective: 900px;
}
section{
    position: relative;
    width: 200px;
    height: 300px;
    cursor: pointer;
    /* 讓其子元素位于3D空間中 */
    transform-style: preserve-3d;
    /* 執(zhí)行動(dòng)畫:動(dòng)畫名稱 時(shí)長(zhǎng) 線性的 無限次播放 */
    animation: rotate 20s linear infinite;
}
section:hover{
    /* 鼠標(biāo)移上動(dòng)畫暫停 */
    animation-play-state: paused;
}
section div{
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    text-align: center;
    /* 設(shè)置元素的倒影效果,below是倒影效果在元素下方,15px是元素和倒影的距離,后面的屬性是設(shè)置倒影漸變 */
    -webkit-box-reflect: below 15px -webkit-linear-gradient(transparent 50%,rgba(255,255,255,0.3));
}
section div img{
    width: 100%;
    height: 100%;
}
section div:nth-child(1){
    transform: rotateY(0deg) translateZ(300px);
}
section div:nth-child(2){
    transform: rotateY(45deg) translateZ(300px);
}
section div:nth-child(3){
    transform: rotateY(90deg) translateZ(300px);
}
section div:nth-child(4){
    transform: rotateY(135deg) translateZ(300px);
}
section div:nth-child(5){
    transform: rotateY(180deg) translateZ(300px);
}
section div:nth-child(6){
    transform: rotateY(225deg) translateZ(300px);
}
section div:nth-child(7){
    transform: rotateY(270deg) translateZ(300px);
}
section div:nth-child(8){
    transform: rotateY(315deg) translateZ(300px);
}

/* 定義旋轉(zhuǎn)動(dòng)畫 */
@keyframes rotate {
    0%{
        transform: rotateY(0deg);
    }
    100%{
        transform: rotateY(360deg);
    }
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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