大家好,又见面了,我是你们的朋友全栈君。
简单实现了js的图片上一张下一张效果,没怎么做css美化单纯就是想记录一下js部分。
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>幻灯片</title>
</head>
<style>
*{
margin:0;
padding:0;
}
#picBox{
margin:100px auto;
width:600px;
height:400px;
}
#pic{
width:600px;
height:400px;
}
#buttonBox{
width:150px;
margin:10px auto;
}
</style>
<body>
<div id="picBox">
<img src="s1.jpg" id="pic">
<div id="buttonBox">
<input type="button" value="上一张" onclick="pre();">
<input type="button" value="下一张" onclick="next();">
</div>
</div>
<script>
var picArr=new Array("s1.jpg","s2.jpg","s3.jpg","s4.jpg");
var index=0;
function next(){
index++;
if(index==picArr.length){
index=0;
}
document.getElementById("pic").src=picArr[index];
}
function pre(){
index--;
if(index<0){
index=picArr.length-1;
}
document.getElementById("pic").src=picArr[index];
}
</script>
</body>
</html>
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/125567.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有