<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
div{
width:300px;
height:300px;
margin:0px auto;
text-align:center;
}
</style>
</head>
<body>
<div>
<img id="pic" src="img/1.jpg" alt="卡通图片"/>
<br>
<button id="last">倒序轮播</button> <button id="next">顺序轮播</button>
<button id="stop">停止轮播</button>
</div>
<script type="text/javascript">
var n=0,flag1=false,flag2=false;
var t1,t2;
var arrayObject=["img/1.jpg","img/2.jpg","img/3.jpg"];
function lastPic(){
var e1=document.getElementById("pic");
n--;
if(n<0){
n=2;}
e1.src=arrayObject[n];
}
function nextPic(){
var e=document.getElementById("pic");
n++;
if(n>2){
n=0;}
e.src=arrayObject[n];
}
function lunBo1(){
if(flag2==false){
t1=window.setInterval("nextPic()",1000);//顺序
flag1=true;
}
else{
clearInterval(t2);
t1=window.setInterval("nextPic()",1000);//顺序
flag1=true;
flag2=false;
}
}
function lunBo2(){
if(flag1==false){
t2=window.setInterval("lastPic()",1000);//倒序
flag2=true;
}
else{
clearInterval(t1);
t2=window.setInterval("lastPic()",1000);//倒序
flag2=true;
flag1=false;
}
}
function Stop(){
clearInterval(t1);
clearInterval(t2);
}
var btnE2=document.getElementById("next");
var btnE1=document.getElementById("last");
var btnE3=document.getElementById("stop");
btnE2.addEventListener("click",lunBo1,false);
btnE3.addEventListener("click",Stop,false);
btnE1.addEventListener("click",lunBo2,false);
</script>
</body>
</html>
qq_39131382
- 粉丝: 1
- 资源: 7
最新资源
- (源码)基于C++和C混合模式的操作系统开发项目.zip
- (源码)基于Arduino的全球天气监控系统.zip
- OpenCVForUnity2.6.0.unitypackage
- (源码)基于SimPy和贝叶斯优化的流程仿真系统.zip
- (源码)基于Java Web的个人信息管理系统.zip
- (源码)基于C++和OTL4的PostgreSQL数据库连接系统.zip
- (源码)基于ESP32和AWS IoT Core的室内温湿度监测系统.zip
- (源码)基于Arduino的I2C协议交通灯模拟系统.zip
- coco.names 文件
- (源码)基于Spring Boot和Vue的房屋租赁管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈