美文网首页
轮播图 3D轮播图

轮播图 3D轮播图

作者: 哲_29be | 来源:发表于2018-05-10 22:14 被阅读0次

轮播图

轮播图.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>  

设置perspective属性

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

perspective 属性定义 3D 元素距视图的距离,以像素计。该属性允许您改变 3D 元素查看 3D 元素的视图。
当为元素定义 perspective 属性时,其子元素会获得透视效果,而不是元素本身。
注释:perspective 属性只影响 3D 转换元素。

把图片旋转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) ';
        }

点击按钮时向右或者向左旋转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

相关文章

  • [iOS]定制性强的广告轮播图--SCAdView

    @[无限轮播图] @[3D轮播图] @[广告轮播图] SCAdView Statement If my code ...

  • 无标题文章

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。它们各具特色,各有用处。 1.传统轮播图 第一步...

  • 轮播图

    轮播图分为:传统轮播图、间歇轮播图、呼吸轮播图、无缝滚动轮播图等。 1.传统轮播图 第一步,得到元素 第二步,设置...

  • 现金红包

    每日红包 轮播图 详情图 周末红包 轮播图 详情图 圣诞红包 轮播图 详情图

  • day7_作业

    轮播图1 轮播图2

  • 普通奖品

    卡西欧小方块 轮播图 详情图 三只松鼠大礼包 轮播图 详情图 天猫精灵 轮播图 详情图 小米蓝牙无线耳机 轮播图 ...

  • 轮播图心得

    轮播图 写轮播图之前我们要认识到几个问题:一、什么是轮播图?二、怎么实现轮播效果?三、轮播图还有什么小功能可以实现...

  • 第五周学习内容

    焦点图轮播特效之原理、焦点图轮播样式之布局、焦点图轮播之箭头切换、焦点图轮播之无限滚动。 js简介、用法、输出。

  • 轮播图 3D轮播图

    轮播图 github地址:https://github.com/zheever/circle_album/tree...

  • 三种样式的轮播图

    一、100%比例轮播图 HTML代码 CSS样式 js代码 二、手动箭头轮播图 三、简易轮播图

网友评论

      本文标题:轮播图 3D轮播图

      本文链接:https://www.haomeiwen.com/subject/bontdftx.html