網站首頁 編程語言 正文
本文實例為大家分享了jQuery實現選項卡嵌套效果的具體代碼,供大家參考,具體內容如下
描述: ??
1.劃上底部a的每一個菜單 讓頂部的標簽span的內容變成對應的a的內容
2.劃上左邊的li 切換到右側對應的div
<!DOCTYPE html> <html lang="en"> ? <head> ? ? <meta charset="UTF-8"> ? ? <meta http-equiv="X-UA-Compatible" content="IE=edge"> ? ? <meta name="viewport" content="width=device-width, initial-scale=1.0"> ? ? <title>Document</title> ? ? <style> ? ? ? ? * { ? ? ? ? ? ? padding: 0; ? ? ? ? ? ? margin: 0; ? ? ? ? ? ? list-style: none; ? ? ? ? ? ? text-decoration: none; ? ? ? ? } ? ? ? ? ? .wrap { ? ? ? ? ? ? width: 800px; ? ? ? ? ? ? height: 400px; ? ? ? ? ? ? border: 2px solid blue; ? ? ? ? ? ? margin: 20px auto; ? ? ? ? ? ? display: flex; ? ? ? ? } ? ? ? ? ? .wrap>ul { ? ? ? ? ? ? width: 150px; ? ? ? ? ? ? height: 100%; ? ? ? ? } ? ? ? ? ? .wrap>ul li { ? ? ? ? ? ? height: 100px; ? ? ? ? ? ? background: red; ? ? ? ? ? ? text-align: center; ? ? ? ? ? ? line-height: 100px; ? ? ? ? ? ? color: #fff; ? ? ? ? ? ? font-size: 30px; ? ? ? ? ? ? border-bottom: 1px solid blue; ? ? ? ? ? ? box-sizing: border-box; ? ? ? ? } ? ? ? ? ? .wrap>ul .active { ? ? ? ? ? ? background: yellow; ? ? ? ? ? ? color: #fff; ? ? ? ? } ? ? ? ? ? .wrap>.cont { ? ? ? ? ? ? position: relative; ? ? ? ? ? ? width: 650px; ? ? ? ? ? ? height: 400px; ? ? ? ? ? ? background: cadetblue; ? ? ? ? } ? ? ? ? ? .wrap>.cont>.inner { ? ? ? ? ? ? position: absolute; ? ? ? ? ? ? top: 0; ? ? ? ? ? ? left: 0; ? ? ? ? ? ? background: blue; ? ? ? ? ? ? width: 100%; ? ? ? ? ? ? height: 100%; ? ? ? ? ? ? box-sizing: border-box; ? ? ? ? ? ? display: none; ? ? ? ? } ? ? ? ? ? .wrap>.cont>.inner.active { ? ? ? ? ? ? display: block; ? ? ? ? } ? ? ? ? ? .wrap>.cont>.inner>span { ? ? ? ? ? ? display: inline-block; ? ? ? ? ? ? width: 100%; ? ? ? ? ? ? height: 350px; ? ? ? ? ? ? background: lightgreen; ? ? ? ? ? ? text-align: center; ? ? ? ? ? ? line-height: 350px; ? ? ? ? ? ? font-size: 50px; ? ? ? ? ? ? color: #fff; ? ? ? ? } ? ? ? ? ? .wrap>.cont>.inner>p { ? ? ? ? ? ? display: flex; ? ? ? ? } ? ? ? ? ? .wrap>.cont>.inner>p>a { ? ? ? ? ? ? line-height: 50px; ? ? ? ? ? ? color: #fff; ? ? ? ? ? ? background: purple; ? ? ? ? ? ? flex-grow: 1; ? ? ? ? ? ? text-align: center; ? ? ? ? } ? ? ? ? ? .wrap>.cont>.inner>p>a.active { ? ? ? ? ? ? background: #fff; ? ? ? ? ? ? color: #000; ? ? ? ? } ? ? </style> </head> ? <body> ? ? <div class="wrap"> ? ? ? ? <ul> ? ? ? ? ? ? <li class="active">a</li> ? ? ? ? ? ? <li>b</li> ? ? ? ? ? ? <li>c</li> ? ? ? ? ? ? <li>d</li> ? ? ? ? </ul> ? ? ? ? <div class="cont"> ? ? ? ? ? ? <div class="inner active"> ? ? ? ? ? ? ? ? <span>a1</span> ? ? ? ? ? ? ? ? <p> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;" class="active">a1</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">a2</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">a3</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">a4</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">a5</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">a6</a> ? ? ? ? ? ? ? ? </p> ? ? ? ? ? ? </div> ? ? ? ? ? ? <div class="inner"> ? ? ? ? ? ? ? ? <span>b1</span> ? ? ? ? ? ? ? ? <p> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;" class="active">b1</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b2</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b3</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b4</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b5</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b6</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b7</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">b8</a> ? ? ? ? ? ? ? ? </p> ? ? ? ? ? ? </div> ? ? ? ? ? ? <div class="inner"> ? ? ? ? ? ? ? ? <span>c1</span> ? ? ? ? ? ? ? ? <p> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;" class="active">c1</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">c2</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">c3</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">c4</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">c5</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">c6</a> ? ? ? ? ? ? ? ? </p> ? ? ? ? ? ? </div> ? ? ? ? ? ? <div class="inner"> ? ? ? ? ? ? ? ? <span>d1</span> ? ? ? ? ? ? ? ? <p> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;" class="active">d1</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">d2</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">d3</a> ? ? ? ? ? ? ? ? ? ? <a href="javascript:;">d4</a> ? ? ? ? ? ? ? ? </p> ? ? ? ? ? ? </div> ? ? ? ? </div> ? ? </div> ? ? <script src="./js/jquery.js"></script> ? ? <script> ? ? ? ? // 劃上底部的a 將span的內容改變 ? ? ? ? $('p a').mouseenter(function () { ? ? ? ? ? ? ? console.log($(this).addClass('active').siblings().removeClass('active').parent().prev().html($(this).html())); ? ? ? ? }); ? ? ? ? // 劃上左側每一個li ?顯示右側對應的inner inner和li下標是一致的 ? ? ? ? $('ul li').mouseenter(function () { ? ? ? ? ? ? ? ?var ind = $(this).index(); ? ? ? ? ? ? ?console.log(ind); ? ? ? ? ? ? ?console.log($(this).addClass('active').siblings().removeClass('active').parent().next().find('.inner').eq(ind).addClass('active').siblings().removeClass('active')); ? ? ? ? }); ? ? </script> </body> ? </html>
原文鏈接:https://blog.csdn.net/qq_48294048/article/details/120157290
相關推薦
- 2022-10-10 VMware?Workstation與Device/Credential?Guard不兼容的解決_V
- 2022-09-22 get方法和post方法的區別
- 2022-07-02 webpack 配置file-loader統一字體打包文件輸出目錄后dist下仍然有字體打包文件
- 2022-02-15 多標簽界面:動態組件 & 異步組件
- 2022-05-13 Scrapy-middlewares對象
- 2022-03-09 C++之const限定符詳解_C 語言
- 2023-04-17 Python屬性私有化詳解_python
- 2022-08-14 Python基礎教程之pip的安裝和卸載_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支