Tab 选项卡切换效果在现如今的网页中,运用的也是比较多的,包括点击切换、滑动切换、延迟切换、自动切换等多种效果
代码如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | <!DOCTYPE html> <html lang= "en" > <head> <meta charset= "UTF-8" > <title>tab</title> <style> *{ margin: 0px; padding: 0px; } .current{ background-color: darkgray; color: yellow; width: 50px; height: 30px; line-height: 30px; float : left; } .top{ float : left; width: 50px; height: 30px; line-height: 30px; } #topMenu{ width: 400px; height: 30px; background-color: aquamarine; margin-left: 400px; float : left; } #bottomMenu{ clear: both; float : left; width: 400px; height: 400px; margin-left: 400px; background-color: chocolate; } .hide{ display: none; } .current-content{ color: blue; font-size: 50px; } </style> </head> <body> <div id= "topMenu" > <div xxx= "c1" class = "top current" onclick= "tab(this)" >menu1</div> <div xxx= "c2" class = "top" onclick= "tab(this)" >menu2</div> <div xxx= "c3" class = "top" onclick= "tab(this)" >menu3</div> </div> <div id= "bottomMenu" > <div id= "c1" class = "current-content" >content1</div> <div id= "c2" class = "hide" >content2</div> <div id= "c3" class = "hide" >content3</div> </div> <script> function tab(self){ $(self).addClass( "current" ); $(self).siblings().removeClass( "current" ); var s=$(self).attr( "xxx" ); $( "#" +s).removeClass( "hide" ); $( "#" +s).addClass( "current-content" ); $( "#" +s).siblings().addClass( "hide" ); $( "#" +s).siblings().removeClass( "current-content" ); } </script> </body> </html> |
程序的运行效果如下:鼠标点击Tab标签,实现标签变色效果,下边的内容变成相应的标签内容.
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持自学编程网。
- 本文固定链接: https://zxbcw.cn/post/186459/
- 转载请注明:必须在正文中标注并保留原文链接
- QQ群: PHP高手阵营官方总群(344148542)
- QQ群: Yii2.0开发(304864863)