JavaScript、tab切换完整版(自动切换、鼠标移入停止、移开运行)
作者:Cakty、Riven 时间:2024-04-22 22:36:28
效果图如下所示:
废话不多说了,直接给大家贴js代码了.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>table切换</title>
<style type="text/css">
*{
padding:
}
button{
width: 95px;
}
.active {
background-color: yellow;
}
#wrap{
width:510px;
overflow: hidden;
margin:0 auto;
}
#inner{
width:9999px;
overflow: hidden;
position: relative;
left:0;
/*transition: left 0.6s;*/
}
#inner a {
float: left;
}
#inner img {
display: block;
width:510px;
}
#main{
text-align: center;
}
</style>
</head>
<body>
<div id="wrap">
<div id="inner">
<a href="###"><img src="img/1.jpg"></a>
<a href="###"><img src="img/2.jpg"></a>
<a href="###"><img src="img/3.jpg"></a>
<a href="###"><img src="img/4.jpg"></a>
<a href="###"><img src="img/5.jpg"></a>
</div>
</div>
<div id="main">
<button class="active">1</button>
<button>2</button>
<button>3</button>
<button>4</button>
<button>5</button>
</div>
<script type="text/javascript">
//获取节点
var btnList = document.getElementsByTagName("button");
var inner = document.getElementById("inner");
//可见宽度
var perWidth = inner.children[0].offsetWidth;
//添加事件
//循环调用事件包装成函数tab
function tab(){
inner.style.left = -perWidth * this.index + "px";
for(var j = 0; j < btnList.length; j++) {
btnList[j].className = "";
}
btnList[index].className = "active";
}
for(var i = 0; i < btnList.length; i++) {
btnList[i].index = i;
btnList[i].onclick = function() {
index=this.index;
tab();
}
}
var index =0;
function prom(){
index ++;
if(index > btnList.length-1){
index = 0;
}
tab();
}
var timer = setInterval(prom,2000);
inner.onmouseover = function() {
// alert("鼠标移入");
clearInterval(timer);
}
inner.onmouseout = function() {
// alert("鼠标移出");
timer = setInterval(prom,2000);
}
</script>
</body>
</html>
以上代码是给大家分享的JavaScript、tab切换完整版(自动切换、鼠标移入停止、移开运行)的全部内容,希望大家喜欢。
标签:javascript,tab,切换
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pytorch--之halfTensor的使用详解
2021-08-18 14:44:08
![](https://img.aspxhome.com/file/2023/4/91964_0s.png)
使用Oracle的Decode函数进行多值判断
2024-01-28 09:12:54
mysql 8.0.22 winx64安装配置方法图文教程
2024-01-16 01:03:20
![](https://img.aspxhome.com/file/2023/1/75651_0s.png)
Python实战项目之MySQL tkinter pyinstaller实现学生管理系统
2024-01-15 16:21:25
![](https://img.aspxhome.com/file/2023/8/99098_0s.jpg)
MDF文件在SQL Server中的恢复技术
2024-01-18 16:25:48
OpenCV实现直线检测
2023-08-14 01:37:35
![](https://img.aspxhome.com/file/2023/2/92492_0s.jpg)
golang原生实现JWT的示例代码
2024-02-08 05:59:51
![](https://img.aspxhome.com/file/2023/5/107365_0s.png)
Python机器学习工具scikit-learn的使用笔记
2021-08-30 10:28:50
![](https://img.aspxhome.com/file/2023/4/100914_0s.png)
pycharm-professional-2020.1下载与激活的教程
2023-03-08 08:12:38
![](https://img.aspxhome.com/file/2023/9/97659_0s.png)
django 发送邮件和缓存的实现代码
2021-05-09 20:53:09
MySQL 的 21 个规范、优化最佳实践!
2024-01-24 13:19:29
![](https://img.aspxhome.com/file/2023/6/70446_0s.png)
Qt数据库应用之实现通用数据生成器
2024-01-16 00:37:49
![](https://img.aspxhome.com/file/2023/1/114931_0s.jpg)
PyCharm代码格式调整方法
2021-05-21 14:59:32
asp数字或者字符排序函数代码
2011-02-24 11:00:00
Python之Pygame的Event事件模块
2021-07-17 06:18:40
python对文档中元素删除,替换操作
2023-08-30 11:28:20
Python 获取指定开头指定结尾所夹中间内容(推荐)
2021-12-13 10:32:05
![](https://img.aspxhome.com/file/2023/8/127778_0s.png)
JS关于刷新页面的相关总结
2024-04-22 12:52:36
利用python和ffmpeg 批量将其他图片转换为.yuv格式的方法
2023-07-27 11:51:43
Python Tkinter GUI编程实现Frame切换
2023-05-08 07:36:28
![](https://img.aspxhome.com/file/2023/1/115511_0s.png)