• 轮播图的做法(更换背景图片)


    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8"
    <title>博客</title>
    <style>

    </style>

    .top-photo{
    670px;
    height: 280px;
    float: left;
    position:relative;
    }
    .top-photo img{
    670px;
    height: 280px;
    display: none;
    }
    .top-photo .selected{
    display: block;
    }
    /*设置浮动*/
    .top-photo ul {
    float: right;
    120px;
    position: absolute;
    top:230px;
    right: 20px;
    }
    .top-photo ul li{
    list-style: none;
    float: left;
    24px;
    height: 24px;
    border-radius:50%;
    background:#666;
    margin-left:5px;
    display: inline-block;
    text-align: center;
    color: white;
    }
    /*设置轮播图里面的圆点颜色*/
    .top-photo ul .orange{
    background:#f77825;
    }
    .imgblock{
    display: block;
    }</style>


    </head>
    <body>

    <!-- 轮播图的四个图片 -->
    <div class="top-photo">
    <img src="images/a1.jpg" alt="" class="selected" >
    <img src="images/a2.jpg" alt="">
    <img src="images/a3.jpg" alt="">
    <img src="images/a4.jpg" alt="">
    <!-- 轮播图的四个圆点 -->
    <ul >
    <li class="orange" data-li="0">1</li>
    <li data-li="1">2</li>
    <li data-li="2">3</li>
    <li data-li="3">4</li>
    </ul>
    </div>

    <script>

    //函数区域
    // var imgs= document.querySelectorAll(".top-photo img");
    function dingshiqi(){

    var orange= document.querySelector(".orange");
    var selected = document.querySelector(".selected");
    // 如果orange有下一个兄弟,那么则把下一个变成orange,
    if(orange.nextElementSibling != null){
    orange.nextElementSibling.className = "orange";
    orange.className = " ";

    selected.nextElementSibling.className = "selected";
    selected.className = "";


    }else{
    // 如果没有下一个兄弟,则父标签的第一个变成orange
    orange.parentNode.firstElementChild.className = "orange";
    orange.className = " ";

    selected.parentNode.firstElementChild.className ="selected";
    selected.className = " ";

    }

    }



    //定时器
    var timer = setInterval(dingshiqi,4000);


    var liArray = document.querySelectorAll(".top-photo ul li");
    // console.log(liArray);
    for(var n=0;n<liArray.length; n++){
    liArray[n].onclick = function(){
    //1.清除之前的定时器
    clearInterval(timer);

    // //2.新建一个开启
    // timer = setInterval(dingshiqi,4000);
    for(var i=0;i<liArray.length; i++){
    liArray[i].className=" ";
    console.log(liArray[i]);
    }
    this.className="orange";
    var imgArray = document.querySelectorAll(".top-photo img");
    for(var a=0;a<imgArray.length;a++){
    imgArray[a].style.display="none";
    number = this.getAttribute("data-li");
    imgArray[number].style.display="block";

    }
    }

    }

    </script>

  • 相关阅读:
    使用.Net Core 2.2创建windows服务
    Ubuntu 18.04 安装部署Net Core、Nginx全过程
    Task的在主线程处理异常信息的Helper类
    行转列的处理。
    netcore 下加密遇到的问题
    关于安装angular-cli环境报错的问题
    64位的windows服务安装问题
    EF.Mysql在codefirst模式下调用存储过程,和再DbFirst模式下的调用
    阿里云消息队列的C#使用http接口发送消息实例
    [转载]EF或LINQ 查询时使用IN并且根据列表自定义排序方法
  • 原文地址:https://www.cnblogs.com/cntt/p/6492859.html
Copyright © 2020-2023  润新知