定时器实现自动轮播图

 

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>滚动图片</title>
    <link rel="stylesheet" href="jingdongshouye.css" />
         <style>
             #wrap{
                 width:600px;
                 height:500px;
                 background:#c8dac9;
                 margin:80px 0  0  100px;
                 position: relative;
                 border:2px solid gray;
                 overflow: hidden;
             }
             #picture{
                 position:absolute;
                 top:0px;
                 left:0px;
             }
             #picture img{
                 float:left;
             }

         </style>
    <script>
        window.οnlοad=function () {
            var obj = document.getElementById('picture');
            var obj1=obj.getElementsByTagName('img');
            var flag = 0;
            var otime = setInterval(show, 1000);

            function show() {
                if (flag ==obj1.length-1) {
                    flag = 0;
                } else {
                    flag++;
                }
                obj.style.top = flag * (-500) + 'px';
            }
        }

    </script>

</head>
<body>
    <div id="wrap">

        <div id="picture">
           <img  src="./photo/a.jpg"  width="600px" height="500px"  alt="" title="" />
           <img  src ="./photo/b.jpg"  width="600px" height="500px"  alt="" title="" />
           <img  src ="./photo/c.jpg"  width="600px" height="500"  alt="" title="" />
           <img src ="./photo/d.jpg"  width="600px" height="500px"  alt="" title="" />
           <img src ="./photo/e.jpg"  width="600px" height="500px"  alt="" title="" />
           <img src ="./photo/f.jpg"  width="600px" height="500px"  alt="" title="" />
        </div>
    </div>

</body>
</html>

转载于:https://my.oschina.net/LeesurYoo/blog/653943

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值