请选择 进入手机版 | 继续访问电脑版

湖南新梦想

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 241|回复: 0

轮播图实现方法

[复制链接]

16

主题

16

帖子

99

积分

注册会员

Rank: 2

积分
99
发表于 2023-6-2 02:18:29 | 显示全部楼层 |阅读模式
<!DOCTYPE html>
<html>               
        <head>
                <meta charset="utf-8">
                <title></title>
                <style>
                       
                        .aa li{
                                /* position: absolute;top: 40%; */
                                display: inline;
                                list-style-type: none;
                                /* border-radius; */
                                border: 1px solid black;
                                border-radius: 50%;
                                width: 20px;
                                height: 20px;
                                text-align: center;
                                line-height: 20px;
                                margin-left: 5px;
                                display: inline-block;
                               
                        }
                       
                       
                        .aa{
                                position: absolute;
                                top: 88%;
                                left: 48%;
                                transform: translate(-50%, -50%);
                        }
                       
                        #tp1
                        {
                               
                                width: 600px;
                                margin: 0 auto;
                        }
                       
                        div
                        {
                                position: relative;
                                text-align: center;
                        }
                       
                        li:hover{
                                cursor: pointer;
                        }
                       
                        li:nth-child(1)
                        {
                                background-color: blue;
                                color: #fff;
                        }
                       
                </style>
               
        </head>
        <body >
                <div id="div">
                        <img src="js/1.jpg" alt="" id="tp1">
                        <!-- <img src="js/2.jpg" alt="" id="tp1">
                        <img src="js/3.jpg" alt="" id="tp1"> -->
                        <ul class="aa">
                                <li>1</li>
                                <li>2</li>
                                <li>3</li>
                        </ul>
                </div>
               
                <script>
                        var time;
                        var list = new Array("js/1.jpg","js/2.jpg","js/3.jpg");
                        var i = 0;
                       
                        function setIndex(index1){
                                i = index1-1;
                                document.getElementById("tp1").src = list;
                                var lis = document.getElementsByTagName("li");
                                for(var index=0;index < lis.length;index++)
                                {
                                        lis[index].style.backgroundColor = "#fff";
                                        lis[index].style.color = "#000";
                                }
                                lis.style.backgroundColor = "blue";
                                lis.style.color = "#fff";
                               
                        }
                       
                        function setImg()
                        {
                                i++;
                                if(list.length == i)
                                {
                                        i = 0;
                                }
                                document.getElementById("tp1").src = list;
                               
                                var lis = document.getElementsByTagName("li");
                                for(var index=0;index < lis.length;index++)
                                {
                                        lis[index].style.backgroundColor = "#fff";
                                        lis[index].style.color = "#000";
                                }
                                lis.style.backgroundColor = "blue";
                                lis.style.color = "#fff";
                        }
                       
                        function myTime()
                        {
                                time = setInterval("setImg()",1000);
                        }
                       
                        function  StopTime()
                        {
                                clearInterval(time)
                        }
                       
                       
                </script>
               
               
        </body>
</html>

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|湖南新梦想 ( 湘ICP备18019834号-2 )

GMT+8, 2023-10-4 14:20 , Processed in 0.041718 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表