js使用面向对象编写下拉菜单
2024-08-30 05:44:31
<html> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
list-style: none;
} .all {
width: 330px;
height: 30px;
background: url(img/bg.jpg) no-repeat;
margin: 100px auto;
line-height: 30px;
text-align: center;
padding-left: 10px;
margin-bottom: 0;
} .all ul li {
width: 100px;
height: 30px;
background: url(img/libg.jpg);
float: left;
margin-right: 10px;
position: relative;
cursor: pointer;
} .all ul ul {
position: absolute;
left: 0;
top: 30px;
display: none;
}
</style>
</head> <body>
<div class="all">
<ul id="list">
<li>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</li>
<li>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</li>
<li>一级菜单
<ul>
<li>二级菜单</li>
<li>二级菜单</li>
<li>二级菜单</li>
</ul>
</li>
</ul>
</div>
</body> </html>
<script>
window.onload = function () {
new ListMenu().init();
} function ListMenu() {
this.list = list.children;
this.init = function () {
for (let i = 0; i < this.list.length; i++) {
this.list[i].onmouseenter = function () {
this.show(this.list[i].children[0]);
}.bind(this)
this.list[i].onmouseleave = function () {
this.hide(this.list[i].children[0]);
}.bind(this)
}
}
this.show = function (obj) {
obj.style.display = "block";
}
this.hide = function (obj) {
obj.style.display = "none";
}
}
</script>
最新文章
- iOS之延时执行(睡眠)的几种方法
- UITextField set placeholderColor and UITextField set clearButton Image
- logo
- [USACO2003][poj2138]Travel Games(dp/最长路)
- 定制linux中的Gtk theme<;一>;如何设置窗口按钮的多态效果
- poj 1113Wall
- 201521123011《Java程序设计》第10周学习总结
- 重新编译Linux内核必要性及其准备工作
- Mysql-5.7.21安装配置
- JS-4-if
- nginx 配置说明
- 第一次使用cisco packet tracer
- SpringBoot集成前端模版(thymeleaf)
- javascript功能插件大集合,写前端的亲们记得收藏
- JS 时间 获取 当天,昨日,本周,上周,本月,上月
- Android解析WindowManagerService(二)WMS的重要成员和Window的添加过程
- 手动安装Chrome截屏控件扩展-Xproer.ScreenCapture(ScreenCapture.crx)
- JavaScript 递归法排列组合二维数组2
- 3.Write Scripts for the mongo Shell-官方文档摘录
- 线段树——hdu1754I Hate It