純Css3手工打造網頁圖片效果

來源:互聯網
上載者:User
  1. 滑鼠移至上方,圖片360度旋轉


    效果:


    代碼:


    <style>
            .rotate-demo {
                width: 220px;
                height: 220px;
                margin: 0 auto;
                background: no-repeat url("images/author.jpg") left top;
                -webkit-background-size: 220px 220px;
                -moz-background-size: 220px 220px;
                background-size: 220px 220px;
                -webkit-border-radius: 110px;
                border-radius: 110px;
                -webkit-transition: -webkit-transform 2s ease-out;
                -moz-transition: -moz-transform 2s ease-out;
                -o-transition: -o-transform 2s ease-out;
                -ms-transition: -ms-transform 2s ease-out;
            }
     
                .rotate-demo:hover {
                    -webkit-transform: rotateZ(360deg);
                    -moz-transform: rotateZ(360deg);
                    -o-transform: rotateZ(360deg);
                    -ms-transform: rotateZ(360deg);
                    transform: rotateZ(360deg);
                }
        </style>
     
    <p class="rotate-demo"></p>


    知識點:CSS3 的transform 屬性可以向元素應用 2D 或 3D 轉換。該屬性允許我們對元素進行旋轉、縮放、移動或傾斜。設定為rotateZ(angle) 實現DOM元素沿著 Z 軸的 3D 旋轉,相關的設定還有rotate、rotate3d、rotateX、rotateY。

  2. 圖片懸停放大



    效果:



    代碼:


    CSS3:
    <style type="text/css">
        .img-container {
            background-color: #000;
            width: 220px;
            height: 220px;
            margin: 20px 50px;
        }
     
        .img {
            -webkit-transform: scale(0.6);
            -moz-transform: scale(0.6);
            -o-transform: scale(0.6);
            -webkit-transition-duration: 0.5s;
            -moz-transition-duration: 0.5s;
            -o-transition-duration: 0.5s;
        }
     
            .img img {
                padding: 1px;
                border-radius: 10px;
                border: 1px solid #fff;
            }
     
            .img:hover {
                -webkit-transform: scale(0.8);
                -webkit-box-shadow: 0px 0px 30px #ccc;
                -moz-transform: scale(0.8);
                -moz-box-shadow: 0px 0px 30px #ccc;
                -o-transform: scale(0.8);
                -o-box-shadow: 0px 0px 30px #ccc;
            }
    </style>
     
    HTML:
    <p class="img-container">
                <p class="img">
                    <img src="http://img.php.cn/upload/article/000/000/013/91ad2d958c7d97417c4d740b2c80e27a-0.jpg">
                </p>
            </p>


    知識點: 同樣用到CSS3的transform屬性,設定scale(x,y),實現DOM元素的2D縮放轉換,相關的還有scale3d、scaleX、scaleY、scaleZ

  3. 實現3D圖片旋轉相簿

    效果:



    代碼:


    CSS:
    <style>
            .carousel-container {
                margin: 20px auto;
                width: 210px;
                height: 140px;
                position: relative;
            }
     
            #carousel {
                width: 100%;
                height: 100%;
                position: absolute;
                transform-style: preserve-3d;
                animation: rotation 20s infinite linear;
            }
     
                #carousel:hover {
                    animation-play-state: paused;
                }
     
                #carousel figure {
                    display: block;
                    position: absolute;
                    width: 186px;
                    height: 116px;
                    left: 10px;
                    top: 10px;
                    background: black;
                    overflow: hidden;
                    border: solid 1px black;
                }
     
                    #carousel figure:nth-child(1) {
                        transform: rotateY(0deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(2) {
                        transform: rotateY(40deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(3) {
                        transform: rotateY(80deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(4) {
                        transform: rotateY(120deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(5) {
                        transform: rotateY(160deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(6) {
                        transform: rotateY(200deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(7) {
                        transform: rotateY(240deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(8) {
                        transform: rotateY(280deg) translateZ(288px);
                    }
     
                    #carousel figure:nth-child(9) {
                        transform: rotateY(320deg) translateZ(288px);
                    }
     
                #carousel .carousel-img {
                    -webkit-filter: grayscale(1);
                    cursor: pointer;
                    transition: all .5s ease;
                    border: none;
                }
     
                    #carousel .carousel-img:hover {
                        -webkit-filter: grayscale(0);
                        transform: scale(1.2,1.2);
                    }
     
            @keyframes rotation {
                from {
                    transform: rotateY(0deg);
                }
     
                to {
                    transform: rotateY(360deg);
                }
            }
        </style>
     
    HTML:
     
    <p class="carousel-container">
            <p id="carousel">
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/91ad2d958c7d97417c4d740b2c80e27a-1.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/91ad2d958c7d97417c4d740b2c80e27a-2.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/91ad2d958c7d97417c4d740b2c80e27a-3.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/91ad2d958c7d97417c4d740b2c80e27a-4.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/91ad2d958c7d97417c4d740b2c80e27a-5.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/2028a2d82c72dc48027911d5df6e0014-6.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/2028a2d82c72dc48027911d5df6e0014-7.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/2028a2d82c72dc48027911d5df6e0014-8.jpg" alt=""></figure>
                <figure><img class="carousel-img" src="http://img.php.cn/upload/article/000/000/013/2028a2d82c72dc48027911d5df6e0014-9.jpg" alt=""></figure>
            </p>
        </p>


    知識點: 還是憑藉CSS3的transform屬性以及animation屬性,使用rotateY定義元素沿著 Y 軸的進行 3D 旋轉,使用translateZ定義元素沿著Z軸進行 3D 轉換;
    同時設定元素的animation屬性實現動畫效果,本文中定義如下:


    animation: rotation 20s infinite linear;


    animation-name(需要綁定到選取器的 keyframe 名稱):rotation的動畫
    animation-duration(完成動畫所花費的時間):20s
    animation-iteration-count(動畫應該播放的次數):infinite(無限次)
    animation-timing-function(動畫的速度曲線):linear(動畫從頭到尾的速度是相同的)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.