js第一份成果

 源代码

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title></title>
    <style type="text/css">
        .wrap {
            width: 800px;
            height: 400px;
            position: relative;
        }

        .list {
            width: 800px;
            height: 400px;
            list-style: none;
            position: relative;
            padding-left: 0px;
        }

        .item {
            margin-top: 50px;
            margin-left: 100px;
            width: 1300px;
            height: 600px;
            color: white;
            font-size: 50px;
            position: absolute;
            opacity: 0;
            transition: all .8s;
        }

        .item:nth-child(1) {
            background-image: url(lun1.png);
        }

        .item:nth-child(2) {
            background-image: url(lun2.png);
        }

        .item:nth-child(3) {
            background-image: url(lun3.png);
        }

        .item:nth-child(4) {
            background-image: url(lun4.png);
        }

        .item:nth-child(5) {
            background-image: url(lun5.png);
        }
        .btn {
            margin-left: 100px;
            margin-top: 150px;
            width: 50px;
            height: 100px;
            position: absolute;
            top: 150px;
            z-index: 100;
        }
        #goPre {
            left: 0px;
        }
        #goNext {
            right: -600px;
        }
        .item.active {
            opacity: 1;
            z-index: 10;
        }
        .pointList{
            padding-left: 0px;
            list-style: none;
            position: absolute;
            right: 20px;
            bottom: 20px;
            z-index: 1000;
        }
        .point{
            width: 10px;
            height: 10px;
            background-color: rgba(0,0,0,0.4);
            border-radius: 100%;
            float: left;
            margin-right: 16px;
            border: solid 2px rgba(255,255,255,0.6);

            cursor: pointer;
        }
        .point.active{
            background-color: rgba(255, 255, 255, 0.5);
        }
    </style>

</head>

<body>
    <div class="wrap">
        <ul class="list">
            <li class="item active"></li>
            <li class="item"></li>
            <li class="item"></li>
            <li class="item"></li>
            <li class="item"></li>
        </ul>
        <button type="button" class="btn" id="goPre"><</button>
        <button type="button" class="btn" id="goNext">></button>
    </div>
    <script type="text/javascript">
        var items = document.getElementsByClassName('item');
        var goPreBtn = document.getElementById('goPre');
        var goNextBtn = document.getElementById('goNext');
        var points = document.getElementsByClassName('point');

        var index = 0;
        var clearActive = function () {
            for (var i = 0; i < items.length; i++) {
                items[i].className = 'item';
            } 
            for(var i = 0; i < points.length; i++)  {
                points[i].className = 'point';
            }
        }
        var goIndex = function () {
            clearActive();
            console.log(index)
            items[index].className = 'item active';
            points[index].className = 'point active';
        }
        var goNext = function(){
            if(index < 4){
                index ++;
            } else{
                index = 0;
            }      
            goIndex();
        }
        var goPre = function(){
            if(index == 0){
                index = 4;
                
            } else{
                index --;
            }
            goIndex();
        }
        goNextBtn.addEventListener('click',function(){
            goNext();
        })
        goPreBtn.addEventListener('click',function(){
            goPre();
        })
    </script>

</body>

</html>

效果图:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值