图片轮换

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            #big{
                width:1560px;
                height: 700px;
                position: relative;
            }
            #big img{
                width:1560px;
                height: 700px;
            }
            .little{
                width: 170px;height: 30px;
                position: absolute;
                bottom: 30px;
                left: 660px;
            }
        </style>
        <script src="Scripts/jquery-1.10.2.js"></script>
        <script type="text/javascript">
            //图片路径
            var list=["img/erji.jpg","img/flower.jpg","img/heart.jpg","img/littlewomen.jpg","img/xiaren.jpg"];
            $(function(){
                var change;//定义变量,接收定时器
                $.each(list,function(index,obj){
                    //生成图片
                    var img=$('<img src="'+this+'"/>').insertBefore(".little");
                    //生成span
                    $('<span>'+(index+1)+'</span>').css({
                        "background-color":"skyblue",
                        "margin":"2px",
                        "width":"30px",
                        "height":"30px",
                        "display":"inline-block",
                        "text-align":"center",
                        "line-height":"30px"
                    }).appendTo(".little");
                })
                //只显示第一张图片
                $("img:gt(0)").hide();
                //第一个数组特别显示
                $("span:eq(0)").css("background-color","pink");
                $("span").hover(function(){
                    //悬浮时显示对应图片
                    $("img").eq(parseInt($(this).text()-1)).show().siblings("img").hide();
                    $("span").eq(parseInt($(this).text()-1)).css("background-color","pink").siblings().css("background-color","skyblue");
                    clearInterval(change);//悬浮时清除定时器
                    showImgIndex=$(this).index();//重置显示元素
                },function(){
                    change = setInterval(showImg,2000);//鼠标离开时继续定时器
                });
                change = setInterval(showImg,2000);//设置定时器
            })
            var showImgIndex=0;//定义变量,控制显示哪张图片
            function showImg(){
                showImgIndex++;
                if(showImgIndex>=5){showImgIndex=0;}
                $("img").eq(showImgIndex).show().siblings("img").hide();
                $("span").eq(showImgIndex).css("background-color","pink").siblings().css("background-color","skyblue");
            }
                
        </script>
    </head>
    <body>
        <div id="big">
            <div class="little">
            </div>
        </div>
    </body>
</html>

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值