html中通过定位 实现下拉,JS+CSS相对定位实现的下拉菜单

本文实例讲述了JS+CSS相对定位实现的下拉菜单。分享给大家供大家参考。具体如下:

这里使用的是相对定位,不过效果还可以,用时候再修整一下,这个只是实现了大概功能,还有许多细节没有修饰。

运行效果截图如下:

52fdceae0da2d85fad87c183873cd07f.png

在线演示地址如下:

具体代码如下:

非定位CSS+Js下拉菜单

#menu {

position: absolute;

font-family: sans-serif;

font-size: 9pt;

}

#menu li {

float: left;

list-style-type: none;

width: 102px;

background-color: skyblue;

border: 1px solid #0066cc;

text-indent: 0px;

margin-left: 3px;

}

#menu li a {

color: blue;

text-decoration: none;

width: 100%;

display: block;

}

#menu li a:hover {

color: white;

}

#menu li ul {

background-color: skyblue;

margin: 0px;

padding: 0px;

}

#menu li ul li {

padding: 0px;

margin: 0px;

float: none;

list-style-type: none;

width: 100px;

text-indent: 0px;

border: none;

}

#menu li ul li a{

color: black;

text-decoration: none;

}

#menu li ul li a:hover{

color: black;

background-color: aqua;

}

var t=false,current;

function SetupMenu() {

if (!document.getElementsByTagName) return;

items=document.getElementsByTagName("li");

for (i=0; i

if (items[i].className != "menu") continue;

thelink=findChild(items[i],"A");

thelink.οnmοuseοver=ShowMenu;

thelink.οnmοuseοut=StartTimer;

if (ul=findChild(items[i],"UL")) {

ul.style.display="none";

for (j=0; j

ul.childNodes[j].οnmοuseοver=ResetTimer;

ul.childNodes[j].οnmοuseοut=StartTimer;

}

}

}

}

function findChild(obj,tag) {

cn = obj.childNodes;

for (k=0; k

if (cn[k].nodeName==tag) return cn[k];

}

return false;

}

function ShowMenu(e) {

if (!e) var e = window.event;

thislink = (e.target) ? e.target: e.srcElement;

ResetTimer();

if (current) HideMenu(current);

thislink = thislink.parentNode;

current=thislink;

ul = findChild(thislink,"UL");

if (!ul) return;

ul.style.display="block";

}

function HideMenu(thelink) {

ul = findChild(thelink,"UL");

if (!ul) return;

ul.style.display="none";

}

function ResetTimer() {

if (t) window.clearTimeout(t);

}

function StartTimer() {

t = window.setTimeout("HideMenu(current)",200);

}

window.οnlοad=SetupMenu;

Menu Test

希望本文所述对大家的JavaScript程序设计有所帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值