CSS3——3D翻轉相簿,css33d翻轉

來源:互聯網
上載者:User

CSS3——3D翻轉相簿,css33d翻轉

transform屬性和transition過渡屬性,結合jQuery代碼實現翻轉功能。

  1 <!DOCTYPE html>  2 <html lang="en">  3 <head>  4     <meta charset="UTF-8">  5     <title>3d翻轉相簿</title>  6     <script src="jquery-3.0.0.min.js"></script>  7     <style>  8         .container {  9             position: relative; 10             width: 560px; 11             height: 380px; 12             margin: 0 auto; 13         } 14         .items { 15             height: 100%; 16             margin: 100px auto; 17             transform-style: preserve-3d; 18             /*實現自動翻轉效果,這裡只設定翻轉一次*/ 19             animation: autoMove 3s 1 linear; 20             /*點擊翻轉  過渡效果*/ 21             transition: all 0.5s; 22         } 23         .item { 24             width: 100%; 25             height: 100%; 26             position: absolute; 27             border: 1px solid #c18;
         
font-size: 50px;
 28         } 29         /*設定不同的bgc,方便區分*/ 30         .item:nth-child(1) { 31             /*background-image: url("images/01.jpg");*/ 32             background-color: #cc1188; 33         } 34         .item:nth-child(2) { 35             /*background-image: url("images/02.jpg");*/ 36             background-color: #0094ff; 37         } 38         .item:nth-child(3) { 39             /*background-image: url("images/03.jpg");*/ 40             background-color: #22ff22; 41         } 42         .item:nth-child(4) { 43             /*background-image: url("images/04.jpg");*/ 44             background-color: #666666; 45         } 46         /*定義動畫*/ 47         @keyframes autoMove { 48             from { } 49             to { 50                 transform: rotateX(360deg); 51             } 52         } 53         /*設定左右翻頁箭頭樣式*/ 54         .left, .right { 55             width: 50px; 56             height: 50px; 57             line-height: 50px; 58             text-align: center; 59             color: white; 60             font-size: 50px; 61             background-color: darkslategray; 62             opacity: .5; 63             position: absolute; 64             top: 50%; 65             margin-top: -25px; 66             cursor: pointer; 67         } 68         .left { 69             left: -25px; 70         } 71         .right { 72             right: -25px; 73         } 74     </style> 75     <script> 76         $(function () { 77             var itemNum = $(".items>.item").length; 78             var itemDeg = 360 / itemNum; 79             $(".items .item").each(function (index, element) { 80                 $(element).css({ 81                     transform: "rotateX(" + index * itemDeg + "deg) translateZ(190px)" 82                 }); 83             }); 84             var count = 0;//記錄點擊的次數,右擊加1,左擊減1 85             $(".container .arrow .right").click(function () { 86                 count++; 87                 $(".items").css({ 88                     transform: "rotateX("+-90*count+"deg)" 89                 }); 90  91             }); 92             $(".container .arrow .left").click(function () { 93                 count--; 94                 $(".items").css({ 95                     transform: "rotateX("+-90*count+"deg)" 96                 }); 97             }); 98         }); 99     </script>100 </head>101 <body>102     <div class="container">103         <div class="items">104             <div class="item">1</div>105             <div class="item">2</div>106             <div class="item">3</div>107             <div class="item">4</div>108         </div>109         <div class="arrow">110             <div class="left"><</div>111             <div class="right">></div>112         </div>113     </div>114 </body>115 </html>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.