JavaScript复习使用定时器的简易式诸葛大力轮播图

先上效果图

在这里插入图片描述

很简单的代码

先创建个文件夹保存成果的照片,然后通过更改src来用定时器循环这些照片
在这里插入图片描述

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,minimal-ui:ios">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="">
    <script src=""></script>
</head>
    <!-- 
        setTimeout(方法或者代码块,时间ms); //在指定的毫秒数后调用函数或计算表达式  可返回一个id
        clearTimeout()  clearTimeout() 方法可取消由 setTimeout() 方法设置的 timeout。    
                        clearTimeout()方法的参数必须是由setTimeout()返回的ID值。
        setInterval(方法或者代码块,执行代码的间隔);//方法可按照指定的周期(以毫秒计)来调用函数或计算表达式 可返回一个id
        clearInterval(id) clearInterval() 方法可取消由 setInterval() 设置的 interval。
                        clearInterval() 方法的参数必须是由 setInterval() 返回的 ID-->
<body>
    
    <img src="img/1.jpeg" width="30%" id="imgs" style="margin-left: 35vw;">
    <script>
        var i=1;
        function f(){
            var imgs=document.getElementById("imgs");
            i++;
            if(i>4){
                i=1;
            }
            imgs.src="img/"+i+".jpeg";
        }
        setInterval(f,2000);

    </script>
    

</body>

</html>

主要是为了复习一下javascript和看一下成果。毕竟成果是大家的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值