3D场景轮播特效

轮播实现

通过观看腾讯公开课学习制作3D场景轮播特效。
点击左右箭头可实现图片3D效果轮播
点击左右箭头可实现图片3D效果轮播

HTML代码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>3D场景轮播</title>
    <link rel="stylesheet" type="text/css" href="css/3d-css.css">
</head>
<body>

    <div id="banner">
        <ul>
            <li class="first">
                <img src="images/1.jpg">
            </li>
            <li class="second secRight">
                <img src="images/2.jpg">
            </li>
            <li class="third thiRight">
                <img src="images/3.jpg">
            </li>
            <li>
                <img src="images/4.jpg">
            </li>
            <li>
                <img src="images/5.jpg">
            </li>
            <li>
                <img src="images/6.jpg">
            </li>
            <li class="third">
                <img src="images/7.jpg">
            </li>
            <li class="second">
                <img src="images/8.jpg">
            </li>
        </ul>

        <div class="btn">
            <div class="left"> < </div>
            <div class="right"> > </div>
        </div>
    </div>
<script type='text/javascript' src="js/Jquery.js"></script>
<script type='text/javascript' src="js/banner.js"></script>
</body>
</html>

CSS代码:

* {
    margin: 0;
    padding: 0;
}

body {
    background: black;
}

#banner {
    position: relative;/*相对定位:参考物*/
    width: 990px;
    height: 540px;
    /*background-color: #d0acac;*/
    margin: 100px auto;
}

#banner ul li {
    position: absolute;/*绝对定位*/
    top: 190px;
    left: 438px;
    list-style: none;
    width: 115px;
    height: 170px;
    border: 1px solid #ccc;
    z-index: 1;
}

#banner ul li.first {
    left: 315px;
    top: 0;
    width: 360px;
    height: 540px;
    z-index: 10;
}

#banner ul li.second {
    left:64px;
    top:35px;
    width: 320px;
    height: 480px;
    z-index: 9;
}

#banner ul li.secRight {
    left:606px;
}

#banner ul li.third {
    width: 240px;
    height: 320px;
    left: 0;
    top: 110px;
    z-index: 8;
}

#banner ul li.thiRight {
    left: 750px;
}

#banner ul li img {
    width: 100%;
    height: 100%;
}

.btn div {
    position: absolute;
    top: 50%;
    width: 60px;
    height: 70px;
    background: rgba(0,0,0,.5);
    color: #fff;
    font-size: 50px;
    font-weight: bold;
    z-index: 100;
    text-align: center;
    cursor: pointer;/*鼠标手的形状*/
    line-height: 70px;
}

.btn div.left {
    left: 0;
}

.btn div.right {
    right: 0;
}

JS代码:

var $li = $("#banner ul li");
var n = 0;
var nowTime = new Date();

$(".btn .left").click(function () {
    if(new Date() - nowTime > 500) {
        move(0);
        nowTime = new Date;
    }
});

$(".btn .right").click(function () {
    if(new Date() - nowTime > 500) {
        move(1);
        nowTime = new Date;
    }
});

function move(direction) {
    var arrW = [], arrH = [], arrL = [], arrT = [], arrZ = [];
    for(var i = 0; i < $li.length; i++) {
        arrW[i] = $li.eq(i).css("width");
        arrH[i] = $li.eq(i).css("height");
        arrL[i] = $li.eq(i).css("left");
        arrT[i] = $li.eq(i).css("top");
        arrZ[i] = $li.eq(i).css("z-index");
    }
    // console.log(arrW);
    for(var i = 0; i < $li.length; i++) {
        if(direction == 0) {//0代表往左边移动
            if(i == 7) {
                n = 0;
            }else {
                n = i + 1;
            }
        } else if(direction == 1) {
            if(i == 0) {
                n = 7;
            } else {
                n = i - 1;
            }
        }

        $li.eq(i).css("z-index", arrZ[n]);
        $li.eq(i).animate({
            "width" : arrW[n],
            "height" : arrH[n],
            "left" : arrL[n],
            "top" : arrT[n]
        }, 500);
    }
}

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基本的3D轮播图特效代码,包含3张图。你可以根据自己的需求修改和调整样式: HTML代码: ``` <div class="carousel"> <figure class="carousel__item"> <img src="https://via.placeholder.com/500x300" alt="Carousel Image 1"> </figure> <figure class="carousel__item"> <img src="https://via.placeholder.com/500x300" alt="Carousel Image 2"> </figure> <figure class="carousel__item"> <img src="https://via.placeholder.com/500x300" alt="Carousel Image 3"> </figure> </div> ``` CSS代码: ``` .carousel { position: relative; width: 100%; height: 300px; perspective: 1000px; } .carousel__item { position: absolute; top: 0; left: 0; width: 100%; height: 100%; transition: transform 0.5s; transform-style: preserve-3d; } .carousel__item:nth-child(1) { transform: translateZ(0); } .carousel__item:nth-child(2) { transform: rotateY(120deg) translateZ(-300px); } .carousel__item:nth-child(3) { transform: rotateY(240deg) translateZ(-300px); } .carousel:hover .carousel__item { transform: rotateY(-120deg); } ``` 解释说明: - `perspective: 1000px;` 设置透视距离为1000像素,用于创建3D效果 - `.carousel__item` 定义轮播项的样式,设置绝对定位、宽高为100%以及3D变换样式 - `.carousel__item:nth-child(n)` 设置每个轮播项的3D变换,其中 `:nth-child(n)` 表示该样式将应用到第n个子元素 - `.carousel:hover .carousel__item` 定义鼠标悬停时的3D变换,将所有轮播项旋转-120度 请注意,这只是一个基本的3D轮播图特效,你可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值