日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

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

發布時間:2023/11/30 javascript 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html中通过定位 实现下拉,JS+CSS相对定位实现的下拉菜单 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例講述了JS+CSS相對定位實現的下拉菜單。分享給大家供大家參考。具體如下:

這里使用的是相對定位,不過效果還可以,用時候再修整一下,這個只是實現了大概功能,還有許多細節沒有修飾。

運行效果截圖如下:

在線演示地址如下:

具體代碼如下:

非定位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程序設計有所幫助。

總結

以上是生活随笔為你收集整理的html中通过定位 实现下拉,JS+CSS相对定位实现的下拉菜单的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。