Ai
1 Star 0 Fork 0

JqueryObjects/preload_ordered

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index2.html 1.89 KB
一键复制 编辑 原始数据 按行查看 历史
涎涎 提交于 2019-04-06 18:13 +08:00 . Add files via upload
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图片预加载之有序加载</title>
<style>
a{
text-decoration: none;
}
.box{
text-align: center;
}
.btn{
display: inline-block;
height: 30px;
line-height: 30px;
border:1px solid #ccc;
background-color:#fff;
padding:0 10px;
margin-right: 50px;
color:#333;
}
.btn:hover{
background: #eee;
}
img{
width: 300px;
height: 200px;
}
</style>
</head>
<body>
<div class="box">
<img src="images/0.jpg" alt="" id="img">
<p>
<a href="javascript:" class="btn" data-control="prev">上一页</a>
<a href="javascript:" class="btn" data-control="next">下一页</a>
</p>
</div>
<script src="js/jquery-3.3.1.js"></script>
<script src="js/preload.js"></script>
<script>
var imgs = [
"images/0.jpg",
"images/1.jpg",
"images/2.jpg",
"images/3.jpg",
"images/4.jpg",
"images/5.jpg",
"images/6.jpg",
"images/7.jpg",
"images/8.jpg",
"images/9.jpg",
"images/10.jpg",
"images/11.jpg",
"images/12.jpg",
"images/13.jpg",
"images/14.jpg",
"images/15.jpg"
],
len = imgs.length,
index = 0;
$.preload(imgs,{
order:'ordered',
});
$(".btn").click(function () {
if($(this).data("control") === "prev"){
//上一张
index = Math.max(0,--index);
}else {
index = Math.min(len - 1,++index)
}
document.title = (index + 1) + "/" + len;
$("#img").attr("src",imgs[index]);
})
</script>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/JqueryObjects/preload_ordered.git
git@gitee.com:JqueryObjects/preload_ordered.git
JqueryObjects
preload_ordered
preload_ordered
master

搜索帮助