js 轮播效果实例分享
作者:xiaoliu12 时间:2023-07-16 00:42:43
html
<!--图片轮播 Start-->
<div class="pics-ul">
<div class="pics-ulleft">
<ul id="allImg">
<li><img src="img/img01.png"/></li>
<li><img src="img/img2.jpg"/></li>
<li><img src="img/img1.jpg"/></li>
<li><img src="img/img3.jpg"/></li>
<li><img src="img/img4.jpg"/></li>
</ul>
<a name="btn" id="prev" class="prev" style="display: block;"></a>
<a name="btn" id="next" class="next" style="display: block;"></a>
<ul id="btn" class="pagination">
<li class="hover"><a href="#0">1</a></li>
<li><a href="#1">2</a></li>
<li><a href="#2">3</a></li>
<li><a href="#3">4</a></li>
<li><a href="#4">5</a></li>
</ul>
</div>
<div class="pics-ulright"><img src="img/imgright.png"/></div>
</div>
<!--图片轮播 End-->
js
/*图片轮播*/
var but1 = document.getElementById("prev");
var abtn = document.getElementById("btn").getElementsByTagName("li"); //获取所有的按钮
var lis = document.getElementById('allImg').getElementsByTagName('li');
var but2 = document.getElementById("next");
var index = 0;
var timer = null;
but2.onclick = function() {
index++;
if (index > lis.length - 1) {
index = 0;
}
setImg(index);
}
but1.onclick = function() {
index--;
if (index < 0) {
index = lis.length - 1;
}
setImg(index);
}
function changeImg() {
if (index == lis.length - 1) { //当到最后一张图片时
index = 0
} else {
index++; //图片索引发生改变
}
setImg(index);
}
function setImg(index) {
for (j = 0; j < lis.length; j++) {
lis[j].style.display = "none";
}
lis[index].style.display = "block";
//按钮的样式要与图片对应
for (var i = 0; i < abtn.length; i++) {
abtn[i].className = ""
}
abtn[index].className = "hover";
}
//自动切换
timer = setInterval(changeImg, 3000);
//按钮
for (var i = 0; i < abtn.length; i++) {
(function() {
var p = i
abtn[p].onclick = function() {
index = p;
setImg(index);
}
})();
}
来源:http://www.cnblogs.com/xiaoliu12/p/6225999.html
标签:js,轮播效果
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python数据库开发之MongoDB安装及Python3操作MongoDB数据库详细方法与实例
2024-01-22 03:53:51
![](https://img.aspxhome.com/file/2023/9/96909_0s.png)
详解利用Python制作中文汉字雨效果
2023-04-26 07:09:17
![](https://img.aspxhome.com/file/2023/3/102973_0s.jpg)
Python实现识别图像中人物的示例代码
2023-11-10 01:59:19
![](https://img.aspxhome.com/file/2023/9/63609_0s.jpg)
python基础之函数的返回值
2022-10-23 23:17:06
![](https://img.aspxhome.com/file/2023/4/105394_0s.jpg)
使用pyecharts在jupyter notebook上绘图
2021-03-17 01:48:35
![](https://img.aspxhome.com/file/2023/9/113139_0s.jpg)
asp如何判断一个电子信箱格式是否有效?
2010-01-12 20:18:00
首页访问感受提升三步曲
2007-12-13 20:36:00
![](https://img.aspxhome.com/file/UploadPic/up/2007121321122194.gif)
使用CSS选择器创建个性化链接样式
2009-06-02 13:07:00
![](https://img.aspxhome.com/file/UploadPic/up/2009060213205633.gif)
TensorFlow实现模型断点训练,checkpoint模型载入方式
2022-01-19 22:32:12
![](https://img.aspxhome.com/file/2023/4/80824_0s.jpg)
Python爬虫实现简单的爬取有道翻译功能示例
2022-05-30 14:08:37
vue自定义js图片碎片轮播图切换效果的实现代码
2024-04-29 13:08:08
JS中模拟函数重载
2008-01-03 16:46:00
Vue中this.$nextTick()的具体使用
2023-07-02 16:59:30
![](https://img.aspxhome.com/file/2023/4/139874_0s.png)
jenkins自动构建发布vue项目的方法步骤
2024-04-30 10:47:14
![](https://img.aspxhome.com/file/2023/5/130045_0s.png)
深入分析JavaScript 事件循环(Event Loop)
2024-04-18 10:51:52
![](https://img.aspxhome.com/file/2023/2/136482_0s.png)
mysql存储过程事务管理简析
2024-01-17 14:30:28
python生成ppt的方法
2021-11-08 11:50:48
![](https://img.aspxhome.com/file/2023/2/134922_0s.jpg)
用js格式化金额可设置保留的小数位数
2024-05-21 10:20:44
解决pycharm回车之后不能换行或不能缩进的问题
2023-06-11 10:45:40
![](https://img.aspxhome.com/file/2023/2/75962_0s.jpg)
Python检测数据类型的方法总结
2022-08-29 22:07:58
![](https://img.aspxhome.com/file/2023/1/65461_0s.png)