JS 无缝轮播(四张图片)

四张图片要实现无缝轮播,我的第一个想法就是立方体,然后每次去转动 然后就自己尝试了一下

CSS部分:

<style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        #focus{
            /*overflow: hidden;*/
            position: relative;
            width: 1100px;
            height: 458px;
            margin: 100px auto;
        }
        #focus #dot{
            position: absolute;
            float: left;
            left: 0;
            bottom: 0;
            height: 35px;
            width: 1100px;
        }
        #focus #dot div{
            position: absolute;
            width: 272px;
            height: 35px;
            line-height: 35px;
            text-align: center;
            background-color: rgba(0,0,0,0.6);
            color: white;
            float: left;
            margin-left: 1px;
            cursor: pointer;
            bottom: 0;
        }
        #focus #dot div:nth-child(1){
            left: 0;
        }
        #focus #dot div:nth-child(2){
            left: 276px;
        }
        #focus #dot div:nth-child(3){
            right: 276px;
        }
        #focus #dot div:nth-child(4){
            right: 0;
        }
        #focus #aImg{
            position: absolute;
            left: 0;
            top: 0;
            width: 1100px;
            height: 458px;
            transition: all ease 0.8s;
            transform-style: preserve-3d;
            transform: rotateY(0deg);
        }
        #focus #aImg li{
            position: absolute;
            width: 1100px;
            height: 458px;
        }
        #focus #aImg li:nth-child(1){
            transform: translateZ(550px);
        }
        #focus #aImg li:nth-child(2){
            transform: rotateY(90deg) translateZ(550px);
        }
        #focus #aImg li:nth-child(3){
            transform: rotateY(180deg) translateZ(550px);
        }
        #focus #aImg li:nth-child(4){
            transform: rotateY(-90deg) translateZ(550px);
        }
        #focus #aImg li img{
            width: 100%;
        }
    </style>

html部分:

<div id="focus">
    <ul id="aImg">
    //图片宽度是 1100px  说出宽度是因为要实现立体拼接 要根据图片的宽度去调整Z轴的距离
        <li><img src="img/shouye1.jpg" alt=""></li> 
        <li><img src="img/shouye5.jpg" alt=""></li>
        <li><img src="img/shouye3.jpg" alt=""></li>
        <li><img src="img/shouye4.jpg" alt=""></li>
    </ul>

</div>

JS代码:

<script>
    var aImg = document.getElementById("aImg");

    var dist = 0;
    function show() {
        aImg.style.transform ="rotateY("+dist*(-90)+ "deg)";
    }
    setInterval(function () {
        dist++;
        show()
    },2000)
</script>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值