本文介绍如何利用JavaScript和CSS技术实现仿Office 2003风格的界面效果。通过特定的CSS样式定义焦点与非焦点状态,结合JavaScript交互,模拟经典办公软件的视觉体验。
仿Office 2003工具条实现
<html> <head> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>仿Office2003的工具条</title> <style> .lostfocus { border: 1px #ffffff solid; background-color: #ffffff; font-size: 12px; font-family: Arial; } .getfocus { border: 1px #08246B solid;background-color: #ffffff; font-family: Arial; font-size: 12px; } .menubar {filter:progid:DXImageTransform.Microsoft.Gradient(gradienttype=0, startcolorstr=#F7F7F7, endcolorstr=#DEDBD6)} .bodybar {filter:progid:DXImageTransform.Microsoft.Gradient(gradienttype=1, endcolorstr=#F7F7F7, startcolorstr=#DEDBD6)} .leftitem { font-family: Arial; font-size: 12px; color: #000000; cursor: hand } .getitem { font-family: Arial; font-size: 12px; color: #000000; cursor: default } .lostitem { cursor: default; color: #808080; font-size: 12px; font-family: Arial; } .menuup { PADDING-LEFT: 4px; PADDING-RIGHT: 4px; CURSOR: hand;} .menuover { PADDING-LEFT: 3px; PADDING-RIGHT: 3px; BACKGROUND-COLOR: #B5BED6; BORDER: 1px solid #08246B; CURSOR: hand; } .lostlist { border: 1px #ffffff solid; background-color: #ffffff; font-size: 12px; font-family: Arial; } .getlist { border: 1px #08246B solid;background-color: #ffffff; font-family: Arial; font-size: 12px; } .listover {BACKGROUND-COLOR: #B5BED6; BORDER-left:1px solid #08246B} .listDiv { filter: alpha(opacity=90,finishopacity=0,style=0) blendtrans(duration=.3); } </style> </head> <body onclick="HideMenu()" style="margin:0px" bgcolor="999999"> <div id=listDiv style='border:1px #636563 solid;VISIBILITY: hidden;POSITION: absolute;overflow:scroll;height:150'></div> <table border="0" width="100%" id="table27" class="bodybar" cellspacing="0" cellpadding="0"> <tr> <td> <table border="0" cellspacing="0" cellpadding="0" height="30"> <tr> <td><table border="0" cellspacing="0" cellpadding="0" height="22"> <tr> <td width="5"></td> <td nowrap align="center" onmouseover="HL_Menu(this,0)" onmouseout="HL_Menu(this,1)" class="menuup"> <table border="0" cellspacing="0" cellpadding="0"><tr><td class="leftitem">文件(F)</td></tr></table> </td> <td width="5"></td> <td nowrap align="center" onmouseover="HL_Menu(this,0)" onmouseout="HL_Menu(this,1)" class="menuup"> <table border="0" cellspacing="0" cellpadding="0"><tr><td class="leftitem">编辑(E)</td></tr></table> </td> </tr> </table></td> </tr> </table> </td> </tr> <tr> <td> <table border="1" width="100" id="table28" cellspacing="0" cellpadding="4" bgcolor="#F7F7F7" style="border-collapse: collapse"> <tr> <td class="menubar"> <table border="0" width="100%" id="table29" cellspacing="0" cellpadding="0"> <tr> <td width="10" nowrap> <table border="0" width="2" cellspacing="0" cellpadding="1" id="table30"> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> </table></td> <td width="35" nowrap><font size="2">姓名</font></td> <td width="130" nowrap> <input type="text" name="T5" size="18" class="lostfocus" gf="0" onmouseover='this.className="getfocus"' onmouseout='if (this.gf=="0") this.className="lostfocus"' onblur='this.className="lostfocus";this.gf="0"' onfocus='this.className="getfocus";this.gf="1"'></td> <td width="35" nowrap><font size="2">密码</font></td> <td width="124" nowrap> <input type="password" name="T6" size="18" class="lostfocus" gf="0" onmouseover='this.className="getfocus"' onmouseout='if (this.gf=="0") this.className="lostfocus"' onblur='this.className="lostfocus";this.gf="0"' onfocus='this.className="getfocus";this.gf="1"'></td> <td width="5" nowrap><img style="border:1px inset" height=14 width=0></td> <td nowrap align="center" onmouseover="HL_Menu(this,0)" onmouseout="HL_Menu(this,1)" class="menuup"> <table cellspacing="0" cellpadding="0" id="table31" width="25"><tr><td nowrap></td><td class="leftitem"> 登陆</td></tr></table> </td> <td width="100%" nowrap> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td> <table border="1" width="100" id="table32" cellspacing="0" cellpadding="4" bgcolor="#F7F7F7" style="border-collapse: collapse"> <tr> <td class="menubar"> <table border="0" width="100%" id="table33" cellspacing="0" cellpadding="0"> <tr> <td width="10" nowrap> <table border="0" width="2" cellspacing="0" cellpadding="1" id="table34"> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> <tr> <td><img style="border:1px inset" height=1 width=1></td> </tr> </table></td> <td width="78" nowrap> <div id="listbox0" class="lostfocus" gf="0" onmouseover='listaction(this,0)' onmouseout='listaction(this,1)' onclick='listaction(this,2,blist1,0)' style="cursor:default"> <table border="0" cellpadding="0" cellspacing="0" width="100" height="18" id="table35"> <tr> <td valign=center style="text-indent:4px"><font size="2" face="Verdana"> <span id=listvalue0> </span></font></td> <td width=12 align="center" class="menubar" id="listbutton0"> <table border="0" cellpadding="0" style="border-collapse: collapse" id="table36"> <tr height=1> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> </tr> <tr height=1> <td></td> <td bgcolor="#000000"></td> <td bgcolor="#000000"></td> <td bgcolor="#000000"></td> <td></td> </tr> <tr height=1> <td></td> <td></td> <td bgcolor="#000000"></td> <td></td> <td></td> </tr> </table></td> </tr> </table> </div></td> <td width="78" nowrap> <div id="listbox1" class="lostfocus" gf="0" onmouseover='listaction(this,0)' onmouseout='listaction(this,1)' onclick='listaction(this,2,blist2,1,100)' style="cursor:default"> <table border="0" cellpadding="0" cellspacing="0" width="100" height="18" id="table37"> <tr> <td valign=center style="text-indent:4px"><font size="2" face="Verdana"><span id=listvalue1> </span></font></td> <td width=12 align="center" class="menubar" id="listbutton1"> <table border="0" cellpadding="0" style="border-collapse: collapse" id="table38"> <tr height=1> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> <td width="1" bgcolor="#000000"></td> </tr> <tr height=1> <td></td> <td bgcolor="#000000"></td> <td bgcolor="#000000"></td> <td bgcolor="#000000"></td> <td></td> </tr> <tr height=1> <td></td> <td></td> <td bgcolor="#000000"></td> <td></td> <td></td> </tr> </table></td> </tr> </table> </div></td> <td width="4" nowrap> </td> <td width="5" nowrap><img style="border:1px inset" height=14 width=0></td> <td nowrap align="center" onmouseover="HL_Menu(this,0)" onmouseout="HL_Menu(this,1)" class="menuup"> <table cellspacing="0" cellpadding="0" id="table39" width="16"><tr><td nowrap></td><td class="leftitem" align=center> <b>B</b></td></tr></table> </td> <td nowrap align="center" onmouseover="HL_Menu(this,0)" onmouseout="HL_Menu(this,1)" class="menuup"> <table cellspacing="0" cellpadding="0" id="table40" width="16"><tr><td nowrap></td><td class="leftitem" align=center> <i> <b>I</b></i></td></tr></table> </td> <td nowrap align="center" onmouseover="HL_Menu(this,0)" onmouseout="HL_Menu(this,1)" class="menuup"> <table cellspacing="0" cellpadding="0" id="table41" width="16"><tr><td nowrap></td><td class="leftitem" align=center> <u> <b>U</b></u></td></tr></table> </td> <td width="100%" nowrap> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <p><font size="2" color="#FFFFFF">工作之余做了这个小东西仿Office 2003的工具条,主要尝试不用任何图片(当然不可能把所有按扭都做出来),所有的控件都是用Css和java-script做的菜单就不做了,偷懒中 感兴趣的朋友可以和我联系,大家交流交流.</font></p> <p><b><font size="2" color="#FFFFFF"> <font color="#FFFFFF" face="Arial">[email]PuterJam@etang.com[/email]</font></font></b> </p> </body> </html> [Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]