• js下拉菜单


    参考文章:https://blog.csdn.net/qq_41485882/article/details/82346429

    鼠标覆盖时展开,展开时不会影响其他元素

    <!DOCTYPE html>
    <html>
    <head>
    	<title></title>
    	<meta charset="utf-8">
    	<style type="text/css">
    		*{margin:0px;padding:0px;}
    		ul{list-style-type:none;}
    		a{text-decoration:none;}
    		.container{
    			505px;
    			margin: 100px auto;
    		}
    		.layer1 li{
    			float: left;
    			 100px;
    			height: 30px;
    			line-height:30px;
    			background-color: #9ed3c8;
    			border-right: 1px solid white;
    			text-align: center;
    			position: relative;		/*不然会被覆盖*/
    			z-index: 999 ;
    		}
    		/*最后一个没有右边框*/
    		.layer1 li:last-child{
    			border-right: none;
    		}
    		.layer1 li:hover{
    			transition: background-color 0.2s linear;
    			background-color: #dc7851;
    		}
    		.layer1>li>a{
    			display: block;
    			 100px;
    			height: 30px;
    			color: white;
    		}
    		.layer1>li>ul>li>a{
    			color: white;
    		}
    		.hidden{
    			display: none;
    		}
    	</style>
    </head>
    <body>
    	<div class="container">
    		<ul class="layer1">
    			<li id="menuitem1">
    				<a href="javascript:;">菜单1</a>
    				<ul id="list1" class="hidden">
    					<li><a href="javascript:;">栏目1</a></li>
    					<li><a href="javascript:;">栏目2</a></li>
    					<li><a href="javascript:;">栏目3</a></li>
    					<li><a href="javascript:;">栏目4</a></li>
    				</ul>
    			</li>
    			<li id="menuitem2">
    				<a href="javascript:;">菜单2</a>
    				<ul id="list2" class="hidden">
    					<li><a href="javascript:;">栏目1</a></li>
    					<li><a href="javascript:;">栏目2</a></li>
    					<li><a href="javascript:;">栏目3</a></li>
    					<li><a href="javascript:;">栏目4</a></li>
    				</ul>
    			</li>
    			<li id="menuitem3">
    				<a href="javascript:;">菜单3</a>
    				<ul id="list3" class="hidden">
    					<li><a href="javascript:;">栏目1</a></li>
    					<li><a href="javascript:;">栏目2</a></li>
    					<li><a href="javascript:;">栏目3</a></li>
    					<li><a href="javascript:;">栏目4</a></li>
    				</ul>
    			</li>
    			<li id="menuitem4">
    				<a href="javascript:;">菜单4</a>
    				<ul id="list4" class="hidden">
    					<li><a href="javascript:;">栏目1</a></li>
    					<li><a href="javascript:;">栏目2</a></li>
    					<li><a href="javascript:;">栏目3</a></li>
    					<li><a href="javascript:;">栏目4</a></li>
    				</ul>
    			</li>
    			<li id="menuitem5">
    				<a href="javascript:;">菜单5</a>
    				<ul id="list5" class="hidden">
    					<li><a href="javascript:;">栏目1</a></li>
    					<li><a href="javascript:;">栏目2</a></li>
    					<li><a href="javascript:;">栏目3</a></li>
    					<li><a href="javascript:;">栏目4</a></li>
    				</ul>
    			</li>
    		</ul>
    	</div>
    </body>
    <script type="text/javascript">
    	window.onload = function(){
    		function mylist(menuitem, list){
    			var menu = document.getElementById(menuitem);
    			var ul = document.getElementById(list);
    			menu.addEventListener("mouseover", function(){
    				ul.style.display = "block";
    			});
    			menu.addEventListener("mouseout", function(){
    				ul.style.display = "none";
    			});
    		}
    		for(var i=1; i<=5; i++){
    			mylist("menuitem" +i, "list" +i);
    		}
    	}
    </script>
    </html>
    
  • 相关阅读:
    历经7年双11实战,阿里巴巴是如何定义云原生混部调度优先级及服务质量的?
    阿里园区的这个“格子间” 成为企业高效协同新利器
    神马是代码简单的cmd模式,这就是!
    什么是javascript的中间件?
    centos 修改主机名
    centos6.5 ssh免密码登陆
    mysql 镜像
    Spring Boot 负载均衡之外置session状态保存
    解决shiro和quartz2 版本冲突问题
    centos6.5 修改java环境变量
  • 原文地址:https://www.cnblogs.com/first-bloodlalala/p/12715520.html
Copyright © 2020-2023  润新知