Home > Article > Web Front-end > Simple web page sliding tab menu effect code implemented in js
This article mainly introduces the simple web page sliding tab menu effect code implemented in js, which can realize the simple function of switching tab labels by sliding the mouse over it. It is very simple and practical. Friends in need can refer to this article
The example describes the simple web page sliding tab menu effect code implemented in js. Share it with everyone for your reference. The details are as follows:
What is introduced here is a simple web sliding door code, implemented based on JS and p CSS. The sliding door menu is a menu that can be switched by just placing the mouse on it. It is only different from the web page tab in the operation form. To change the sliding door tab, just change the onmouseover in the door menu to onclick. After changing it, switch The content requires a mouse click on the door menu.
The screenshot of the running effect is as follows:
The specific code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>网页滑动门菜单</title> <style> * {list-style-type:none; font-size:12px; text-decoration:none; margin:0; padding:0;} .tab{ margin:20px; width:244px; height:200px; overflow:hidden; border:1px #AACCEE solid;} .tab_b{ overflow:hidden; margin:5px; } .menu{overflow:hidden; } .menu li{ display:block; float:left; display: list-item; text-align:center; width:60px; background-color:#EDF4FC;line-height:20px; border-bottom:1px #AACCEE solid;border-right:1px #AACCEE solid; } .menu li a{ display:block;} .menu_d{border-bottom:1px #FFFFFF solid;background-color:#FFFFFF; } .tab ul li.aaa{background: #FFFFFF;border-bottom:0px #FFFFFF solid;} </style> </head> <body> <script language="javascript"> function tabs(n) { var len = 4; for (var i = 1; i <= len; i++) { document.getElementById('tab_a' + i).style.display = (i == n) ? 'block' : 'none'; document.getElementById('tab_' + i).className = (i == n) ? 'aaa' : 'none'; } } </script> <p class="tab"> <ul class="menu" id="menutitle"> <li id="tab_1" class="aaa"><a href="javascript:void(0)" onclick="tabs('1');" >新闻</a></li> <li id="tab_2" ><a href="javascript:void(0)" onmouseover="tabs('2');" >生活</a></li> <li id="tab_3" ><a href="javascript:void(0)" onmouseover="tabs('3');" >滚动</a></li> <li id="tab_4" ><a href="javascript:void(0)" onmouseover="tabs('4');" >旅游</a></li> </ul> <p class="tab_b" id="tab_a1" style="display:block;"> 国内国际新闻</p> <p class="tab_b" id="tab_a2" style="display:none;">本土快乐生活</p> <p class="tab_b" id="tab_a3" style="display:none;">适时新闻滚动</p> <p class="tab_b" id="tab_a4" style="display:none;">期待完美假日</p> </p> </body> </html>