輪播圖 3D輪播圖

輪播圖

輪播圖.gif

主要代碼:

<!DOCTYPE html>  
<html lang="en">  
<head>
    <meta charset="UTF-8">  
    <title>Document</title>
    <style type='text/css'>
        *{
            padding: 0px;
            margin: 0px;
        }

        #photos{
            width: 530px;
            height:300px;
            margin: 100px 0 0 200px;
        }
        
        .button_container {
            width: 530px;
            height:300px;
            position: absolute;
            top: 0px;
            margin: 100px 0 0 200px;
            z-index: 100;
        }

        img{
            width: 530px;
            height: 300px;
            position: absolute;
            border-radius: 10px;
            z-index: 0;
        }

        .prev_button {
            float: left;
            height: 69px;
            width: 41px;
            margin-top: 120px;
            background: url('./images/icon-slides.png') no-repeat;
            background-position: -84px 50%;
        }

        .prev_button:hover {
            background-position:0 50%;
        }

        .next_button {
            float: right;
            height: 69px;
            width: 41px;
            margin-top: 120px;
            background: url('./images/icon-slides.png') no-repeat;
            background-position: -125px 50%;
        }

        .next_button:hover {
            background-position:-42px 50%;
        }
    </style>
</head>  
<body>
    <div class="container">
        <div id="photos">
            <img id="pic0" src="./images/150713416389.jpg" alt="">
            <img id="pic1" src="./images/150719519140.jpg" alt="">
            <img id="pic2" src="./images/150719602492.jpg" alt="">
            <img id="pic3" src="./images/1506434387826.jpg" alt="">
            <img id="pic4" src="./images/1507133690232.jpg" alt="">
            <img id="pic5" src="./images/1507133807172.jpg" alt="">
        </div>
        <div class="button_container">
            <div class="prev_button"></div>
            <div class="next_button"></div>
        </div>
    </div>

    <script>
        var index = 0;
        var photos_num = document.getElementsByTagName("img").length;
        document.getElementsByClassName('prev_button')[0].onclick = function () {
            document.getElementById('pic' + index).style = 'z-index: 0';
            index ++;
            if (index == photos_num) index = 0;
            document.getElementById('pic' + index).style = 'z-index: 50';
        }
        document.getElementsByClassName('next_button')[0].onclick = function () {
            document.getElementById('pic' + index).style = 'z-index: 0';
            index --;
            if (index == -1) index = photos_num - 1;
            document.getElementById('pic' + index).style = 'z-index: 50';
        }
    </script>
</body>  
</html>  

github地址:https://github.com/zheever/circle_album/tree/master/%E8%BD%AE%E6%92%AD%E5%9B%BE


3D輪播圖

參考:https://juejin.im/post/5aeafb0f6fb9a07ac76ea983

3D輪播圖.gif

主要代碼:

<!DOCTYPE html>  
<html lang="en">  
<head>
   <meta charset="UTF-8">  
   <title>Document</title>
   <style type='text/css'>
       *{
           padding: 0px;
           margin: 0px;
       }

       .container{
           perspective: 1600px;
           -webkit-perspective: 1600px;       
       }

       #photos{
           width: 339px;
           height:300px;
           margin: 200px 500px;
           transform-style: preserve-3d;
           transition: all .5s ease;
           -webkit-transform-style: preserve-3d;
           -webkit-transition: all .5s ease;
       }
       
       .button_container {
           width: 339px;
           height:300px;
           position: absolute;
           top: 0px;
           margin: 0 500px;
           transform : translateZ(300px);
           -webkit-transform : translateZ(300px);
       }

       img{
           width: 339px;
           height: 300px;
           position: absolute;
           border-radius: 10px;
       }

       .prev_button {
           float: left;
           height: 69px;
           width: 41px;
           margin-top: 120px;
           background: url('./images/icon-slides.png') no-repeat;
           background-position: -84px 50%;
       }

       .prev_button:hover {
           background-position:0 50%;
       }

       .next_button {
           float: right;
           height: 69px;
           width: 41px;
           margin-top: 120px;
           background: url('./images/icon-slides.png') no-repeat;
           background-position: -125px 50%;
       }

       .next_button:hover {
           background-position:-42px 50%;
       }
   </style>
</head>  
<body>
   <div class="container">
       <div id="photos">
           <img class="pic1" src="./images/150713416389.jpg" alt="">
           <img class="pic2" src="./images/150719519140.jpg" alt="">
           <img class="pic3" src="./images/150719602492.jpg" alt="">
           <img class="pic4" src="./images/1506434387826.jpg" alt="">
           <img class="pic5" src="./images/1507133690232.jpg" alt="">
           <img class="pic6" src="./images/1507133807172.jpg" alt="">
       </div>
       <div class="button_container">
           <div class="prev_button"></div>
           <div class="next_button"></div>
       </div>
   </div>

   <script>
       var photos_container = document.getElementById("photos");
       var photos_list = photos_container.getElementsByTagName("img");
       var photos_num = photos_list.length;
       var ang = Math.floor(360 / photos_num);
       for(var i = 0; i < photos_num; i++){
           photos_list[i].style = 'transform : rotateY(' + ang*i + 'deg) translateZ(300px) ';
       }

       var rotate_deg = 0;
       document.getElementsByClassName('prev_button')[0].onclick = function () {
           rotate_deg += ang;
           photos_container.style = 'transform : rotateY(' + rotate_deg + 'deg)';
       }
       document.getElementsByClassName('next_button')[0].onclick = function () {
           rotate_deg -= ang;
           photos_container.style = 'transform : rotateY(' + rotate_deg + 'deg)';
       }
   </script>
</body>  
</html>  

設(shè)置perspective屬性

.container{
            perspective: 1600px;
            -webkit-perspective: 1600px;       
        }

perspective 屬性定義 3D 元素距視圖的距離票顾,以像素計(jì)础浮。該屬性允許您改變 3D 元素查看 3D 元素的視圖。
當(dāng)為元素定義 perspective 屬性時(shí)奠骄,其子元素會(huì)獲得透視效果豆同,而不是元素本身。
注釋:perspective 屬性只影響 3D 轉(zhuǎn)換元素含鳞。

把圖片旋轉(zhuǎn)60度影锈,再在Z軸上偏移300px,形成立體的六邊形

        var photos_container = document.getElementById("photos");
        var photos_list = photos_container.getElementsByTagName("img");
        var photos_num = photos_list.length;
        var ang = Math.floor(360 / photos_num);
        for(var i = 0; i < photos_num; i++){
            photos_list[i].style = 'transform : rotateY(' + ang*i + 'deg) translateZ(300px) ';
        }

點(diǎn)擊按鈕時(shí)向右或者向左旋轉(zhuǎn)60度

        var rotate_deg = 0;
        document.getElementsByClassName('prev_button')[0].onclick = function () {
            rotate_deg += ang;
            photos_container.style = 'transform : rotateY(' + rotate_deg + 'deg)';
        }
        document.getElementsByClassName('next_button')[0].onclick = function () {
            rotate_deg -= ang;
            photos_container.style = 'transform : rotateY(' + rotate_deg + 'deg)';
        }

github地址:https://github.com/zheever/circle_album/tree/master/3D%E8%BD%AE%E6%92%AD%E5%9B%BE

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末蝉绷,一起剝皮案震驚了整個(gè)濱河市鸭廷,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌熔吗,老刑警劉巖辆床,帶你破解...
    沈念sama閱讀 216,496評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異桅狠,居然都是意外死亡讼载,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,407評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門中跌,熙熙樓的掌柜王于貴愁眉苦臉地迎上來咨堤,“玉大人,你說我怎么就攤上這事漩符∫淮” “怎么了?”我有些...
    開封第一講書人閱讀 162,632評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵陨仅,是天一觀的道長津滞。 經(jīng)常有香客問我,道長灼伤,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,180評(píng)論 1 292
  • 正文 為了忘掉前任咪鲜,我火速辦了婚禮狐赡,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘疟丙。我一直安慰自己颖侄,他們只是感情好鸟雏,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,198評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著览祖,像睡著了一般孝鹊。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上展蒂,一...
    開封第一講書人閱讀 51,165評(píng)論 1 299
  • 那天又活,我揣著相機(jī)與錄音,去河邊找鬼锰悼。 笑死柳骄,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的箕般。 我是一名探鬼主播耐薯,決...
    沈念sama閱讀 40,052評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼丝里!你這毒婦竟也來了曲初?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,910評(píng)論 0 274
  • 序言:老撾萬榮一對情侶失蹤杯聚,失蹤者是張志新(化名)和其女友劉穎臼婆,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體械媒,經(jīng)...
    沈念sama閱讀 45,324評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡目锭,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,542評(píng)論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了纷捞。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片痢虹。...
    茶點(diǎn)故事閱讀 39,711評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖主儡,靈堂內(nèi)的尸體忽然破棺而出奖唯,到底是詐尸還是另有隱情,我是刑警寧澤糜值,帶...
    沈念sama閱讀 35,424評(píng)論 5 343
  • 正文 年R本政府宣布丰捷,位于F島的核電站,受9級(jí)特大地震影響寂汇,放射性物質(zhì)發(fā)生泄漏病往。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,017評(píng)論 3 326
  • 文/蒙蒙 一骄瓣、第九天 我趴在偏房一處隱蔽的房頂上張望停巷。 院中可真熱鬧,春花似錦、人聲如沸畔勤。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,668評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽庆揪。三九已至式曲,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間缸榛,已是汗流浹背吝羞。 一陣腳步聲響...
    開封第一講書人閱讀 32,823評(píng)論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留仔掸,地道東北人脆贵。 一個(gè)月前我還...
    沈念sama閱讀 47,722評(píng)論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像起暮,于是被迫代替她去往敵國和親卖氨。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,611評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容