tab切换控制显示隐藏的超级简单实用方法
来源:互联网 发布:ubuntu离线安装mysql 编辑:程序博客网 时间:2024/06/07 16:50
废话不多说,直接上代码
html中:
<div class="cloud_content"><div class="tabContent" style="background: pink;"></div><div class="tabContent" style="background: skyblue;display: none;"></div><div class="tabContent" style="background: honeydew;display: none;"></div><div class="tabContent" style="background: blanchedalmond;display: none;"></div><div class="foreTab" id="foreTab"><ul><li><img src="img/szyd.png"/></br><span>第一</span></li><li><img src="img/work.png"/></br><span>第二</span></li><li><img src="img/xzzf.png"/></br><span>第三</span></li><li><img src="img/zcdj.png"/></br><span>第四</span></li></ul></div></div>
css中:
.cloud_content{position: relative;height: 526px;}.tabContent{width: 872px;height: 526px;position: absolute;left: 0;}.foreTab{width: 130px;position: absolute;right: 0;}.foreTab ul li{width: 130px;height: 130px;border: 1px solid #FFFFFF;background-color: #adadad;text-align: center;color: #FFFFFF;}.foreTab ul li img{margin-top: 30px;margin-bottom: 5px;}
js中:
$(function(){$("#foreTab ul li:eq(0)").css("background-color","#1B71AB");//默认第一个选中 $("#foreTab").find("li").each(function(i){//遍历需要切换的标签 this.index = i;//给其自定义一个属性 $(this).on('click',function(){//给当前的加一个点击事件 var self = this;//定义一个self属性等于this $(this).css("background-color","#1B71AB").siblings().css("background-color","#ADADAD");//给当前点击的添加属性(类名),将其所有的兄弟移除该属性(类名) $(".cloud_content .tabContent").each(function(j){//将需要随着切换而需显示隐藏的元素遍历 $(this).css('display','none');//先隐藏 if(j==self.index){//判断当前元素的索引号是否等于当前点击的标签的索引号 $(this).css("display",'block');//等于就让其显示 } }) }) })})
看看效果图吧:
需要的欢迎采纳哦,最后,如果你需要的切换标签(也即上图右边里面的小图标是两张图片切换的话)里的图片改变,同切换左边模块一样,这里再附上一点,仅供参考
var oldImg = ['a.png','b.png','c.png','d.png'], //原来图片名newImg = ['aa.png','bb.png','cc.png','dd.png']; //切换后的图片名
$('.clickchange img').each(function(j){ //遍历需要改变的图片$(this).attr('src','../res/imgs/jjjd/'+oldImg[j]); //给图片添加src属性,路径拼接if(j==self.index){ //判断当前图片的索引号是否等于当前点击的标签的索引号$(this).attr('src','../res/imgs/jjjd/'+newImg[j]); //是就给其添加新的src属性}});
阅读全文
0 0
- tab切换控制显示隐藏的超级简单实用方法
- jquery 简单实用的Tab切换
- 简单实用的TAB切换标签
- jQuery控制元素显示、隐藏、切换、滑动的方法
- jQuery控制元素显示、隐藏、切换、滑动的方法
- Tab的切换问题:Tab的显示和隐藏
- JQ简单的radio切换显示、隐藏
- 很实用的jQuery事件 - toggle() 方法,简单实现显示隐藏的功能
- 实用简洁的TAB切换函数
- 一个简单的tab切换
- 最简单的tab切换
- 最简单的tab切换
- tab切换的简单实现
- js简单的tab切换
- 针对TAB切换的隐藏区域
- jquery实现的非常简单实用带有渐变切换效果的tab选项卡
- 最简洁实用的tab切换,tab选项卡
- Ionic3隐藏tab的方法
- 重新安装JDK后,tomcat 7 无法启动
- UE4学习笔记16th:编辑PawnMovementComponent
- Spring Boot基础知识(三)----配置文件等零碎知识
- subplot画图添加总标题
- 欧几里得的游戏 洛谷p1290
- tab切换控制显示隐藏的超级简单实用方法
- zabbix使用自定义key进行监控
- IOS人脸识别开发入门教程--人脸检测篇
- Scrapy抓取Ajax动态页面
- Oracle VM VirtualBox Linux 虚拟机扩容
- 在Linux环境下设置ArcGIS的 Server,Portal和DataStore服务开机自启
- 在Unity中通过触摸屏幕实现模型的旋转和缩放
- HDU6178-Monkeys
- Ignatius and the Princess IV