百变鹏仔-专注前端行业精选
jq简单实现选项卡效果
作者:鹏仔先生日期:2020-06-19 15:36:34浏览:4266分类:JavaScript
很简单的一个demo,平时经常用到,整理下,每次用直接复制粘贴挺香的。
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JQ实现选项卡-</title> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script> <style> *{ margin: 0; padding: 0; } body{ padding: 300px; box-sizing: border-box; } .tab-box{ width: 500px; display: flex; align-items: center; } .tab-box span{ color: #fff; font-size: 16px; line-height: 30px; text-align: center; display: inline-block; width: 100px; background: #000; cursor: pointer; } .tab-box .active{ background: skyblue; } .content div{ display: none; } .content .active{ display: block; } </style> </head> <body> <div class="tab-box"> <span class="active">tab-1</span> <span>tab-2</span> <span>tab-3</span> <span>tab-4</span> <span>tab-5</span> </div> <div class="content"> <div class="active">内容1</div> <div>内容2</div> <div>内容3</div> <div>内容4</div> <div>内容5</div> </div> </body> </html> <script> $(".tab-box span").click(function(){ // 给当前的添加类名,并清除同级其他的类名 $(this).addClass("active").siblings().removeClass("active"); // 获取当前点击的索引 var index = $(this).index(); // 对应索引对应的添加类名active,并清楚同级其他的类名 $(this).parent().siblings().children().eq(index).addClass("active").siblings().removeClass("active"); }) </script>
- 上一篇:使用c3动画实现摇铃铛效果
- 下一篇:使用jq实现二级菜单效果,jq下拉菜单效果
手机扫码访问
猜你还喜欢
- 04-19 VUE实现点击复制
- 04-16 vue将页面生成图片 vue生成海报
- 04-16 vue路由切换滑动效果 vue页面跳转交互 vue实现动画跳转
- 04-16 table固定表头和列 css实现表格固定表头
- 04-07 vue跳转页面清除历史记录,页面跳转删除历史记录
- 02-22 VUE You are using the runtime-only build of Vue where the template compiler is not available. Either
- 01-19 elementui多选上传 before-upload 格式效验错误总会触发before-remove (elementui多选上传on-success只执行了一次,只上传成功了一条)
- 10-08 vue按钮限制连点封装 自定义指令限制连点
- 09-14 nvm常用命令有哪些?nvm如何切换node版本?nvm如何下载node?
- 08-19 使用HBuilderX将vue或H5项目打包app
- 07-15 小程序嵌入网页向小程序跳转并传参,微信小程序中实现公众号授权获取openId
- 07-13 vue中实现文件批量打包压缩下载(以及下载跨域问题分析)
暂无评论,来添加一个吧。