• html-网站菜单-点击菜单展开相应的导航栏,加减号可切换


    一、效果图

    1.点击显示菜单栏,点击x号关闭;
    2.点击一级菜单,展开显示二级,并且加号变为减号;
    3.点击其他一级导航,自动收起展开的导航。
    在这里插入图片描述

    请添加图片描述

    二、代码实现

    DOCTYPE html>
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    		<meta http-equiv="content-language" content="zh-CN" />
    		<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no" />
    		<meta name="apple-mobile-web-app-capable" content="yes" />
    		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
    		<meta name="format-detection" content="telephone=no" />
    		<meta name="Keywords" content="" />
    		<meta name="Description" content="" />
    		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    		<title>title>
    		<script src="static/js/jquery-1.11.3.js" type="text/javascript" charset="utf-8">script>
    		<style>
    			.header {
    				position: relative;
    				height: 100px;
    				padding: 30px;
    				box-sizing: border-box;
    			}
    
    			.header .header-right {
    				position: relative;
    				float: right;
    			}
    
    			.header .l-toggle {
    				float: left;
    				width: 38px;
    				height: 20px;
    				cursor: pointer;
    				z-index: 99;
    				position: relative;
    			}
    
    			.header .l-toggle span {
    				position: absolute;
    				top: 0;
    				right: 0;
    				left: 0;
    				display: block;
    				width: 26px;
    				height: 2px;
    				background-color: #000;
    			}
    
    			.header .l-toggle .line1 {
    				margin: 0 auto;
    				-webkit-transform: rotate(0);
    				-ms-transform: rotate(0);
    				transform: rotate(0);
    				-webkit-transition: margin .3s .5s ease, -webkit-transform .5s ease;
    				transition: margin .3s .5s ease, transform .5s ease;
    			}
    
    			.header .l-toggle .line2 {
    				margin: 8px auto 0;
    			}
    
    			.header .l-toggle .line3 {
    				margin: 16px auto auto;
    				-webkit-transform: rotate(0);
    				-ms-transform: rotate(0);
    				transform: rotate(0);
    				-webkit-transition: margin .3s .5s ease, -webkit-transform .5s ease;
    				transition: margin .3s .5s ease, transform .5s ease;
    			}
    
    			.header .l-toggle.hover span {
    				background: #828282;
    			}
    
    			.header .l-toggle.hover .line1 {
    				-webkit-transform: rotate(45deg);
    				-ms-transform: rotate(45deg);
    				transform: rotate(45deg);
    				margin: 8px auto 0;
    				-webkit-transition: margin .3s ease, -webkit-transform .5s .3s ease;
    				transition: margin .3s ease, transform .5s .3s ease;
    			}
    
    			.header .l-toggle.hover .line3 {
    				-webkit-transform: rotate(-45deg);
    				-ms-transform: rotate(-45deg);
    				transform: rotate(-45deg);
    				margin: 8px auto 0;
    				-webkit-transition: margin .3s ease, -webkit-transform .5s .3s ease;
    				transition: margin .3s ease, transform .5s .3s ease;
    			}
    
    			.header .sub-menu {
    				width: 217px;
    				height: auto;
    				position: absolute;
    				right: 30px;
    				top: 20px;
    				z-index: 2;
    				background: rgba(255, 255, 255, 0.83);
    				padding: 70px 24px 30px;
    				box-sizing: border-box;
    				display: none;
    				border: 1px solid rgba(0, 0, 0, 0.2);
    			}
    
    			.header.active .line {
    				height: 100vh;
    				background: rgba(130, 130, 130, 0.3);
    			}
    
    
    			.header .sub-menu_ul {
    				width: 100%;
    				padding: 0;
    			}
    
    			.header .sub-menu_ul li {
    				width: 100%;
    				margin-bottom: 20px;
    				font-family: Microsoft YaHei UI;
    				position: relative;
    				text-align: right;
    				list-style: none;
    			}
    
    			.header .sub-menu_ul li .li_title {
    				display: flex;
    				align-items: center;
    				justify-content: space-between;
    				font-size: 18px;
    				font-weight: bold;
    				color: #ABABAB;
    				/* color: #333333; */
    				cursor: pointer;
    			}
    
    			.header .sub-menu_ul li .li_title span {
    				color: #858585;
    				font-size: 20px;
    				display: none;
    			}
    
    			.header .sub-menu_ul li .li_title .spanAdd {
    				display: block;
    			}
    
    			.menu_li_active .spanAdd {
    				display: none !important;
    			}
    
    			.menu_li_active .spanSub {
    				display: block !important;
    			}
    
    			.menu_li_active a {
    				color: #333 !important;
    				top: -7px !important;
    
    			}
    
    			.header .sub-menu_ul li .li_title a {
    				position: absolute;
    				right: 0;
    				top: -14px;
    				z-index: 999;
    				font-size: 18px;
    				font-weight: bold;
    				color: #ABABAB;
    				width: 66%;
    			}
    
    			.header .sub-menu_ul li a {
    				width: 100%;
    				display: block;
    				font-size: 14px;
    				font-weight: 400;
    				color: #333333;
    				margin-top: 15px;
    				transition: 0.5s;
    				text-decoration: none;
    			}
    
    			.header .sub-menu_ul li a:hover {
    				text-decoration: underline;
    			}
    
    			.header .sub-menu_ul li .li_con {
    				display: none;
    			}
    
    		style>
    
    	head>
    
    	<body>
    		
    		<header class="header">
    			<div class="header-right">
    				<div id="toggle" class="l-toggle">
    					<span class="line1">span>
    					<span class="line2">span>
    					<span class="line3">span>
    				div>
    			div>
    			<div class="sub-menu">
    				<ul class="sub-menu_ul">
    					<li>
    						<div class="li_title">
    							<span class="spanAdd">+span>
    							<span class="spanSub" style="font-size: 29px;">-span>
    							<a href="aboutHongtian.html">走进鸿天a>
    						div>
    						<div class="li_con">
    							<a href="aboutHongtian.html">关于鸿天a>
    							<a href="aboutHistory.html">发展历程a>
    							<a href="aboutCulture.html">企业文化a>
    							<a href="aboutHonors.html">荣誉资质a>
    							<a href="aboutBrand.html">企业品牌a>
    						div>
    					li>
    
    					<li>
    						<div class="li_title">
    							<span class="spanAdd">+span>
    							<span class="spanSub" style="font-size: 29px;">-span>
    							<a href="savingList.html">集团业务a>
    						div>
    						<div class="li_con">
    							<a href="savingEnvirProtection.html">ODM供应链a>
    							<a href="savingEnvirProtection.html">品牌零售a>
    						div>
    					li>
    					<li>
    						<div class="li_title">
    							<span class="spanAdd">+span>
    							<span class="spanSub" style="font-size: 29px;">-span>
    							<a href="savingList.html">技术研发a>
    						div>
    						<div class="li_con">
    							<a href="savingEnvirProtection.html">研发中心a>
    							<a href="savingEnvirProtection.html">印绣中心a>
    							<a href="savingEnvirProtection.html">检测中心a>
    						div>
    					li>
    					<li>
    						<div class="li_title">
    							<span class="spanAdd">+span>
    							<span class="spanSub" style="font-size: 29px;">-span>
    							<a href="savingList.html">可持续发展a>
    						div>
    						<div class="li_con">
    							<a href="savingEnvirProtection.html">节能环保a>
    							<a href="savingEnvirProtection.html">慈善公益a>
    							<a href="savingEnvirProtection.html">校企合作a>
    						div>
    					li>
    					<li>
    						<div class="li_title">
    							<span class="spanAdd">+span>
    							<span class="spanSub" style="font-size: 29px;">-span>
    							<a href="focusHongtian.html">聚焦鸿天a>
    						div>
    						<div class="li_con">
    							<a href="focusHongtian.html">企业动态a>
    							<a href="focusHongtian.html">品牌动态a>
    							<a href="focusHongtian.html">鸿天人家a>
    							<a href="focusHongtian.html">红色党建a>
    						div>
    					li>
    					<script>
    						$(function() {
    							$('.sub-menu_ul li').click(function() {
    								$(this).find('.li_con').slideToggle()
    								$(this).siblings().find('.li_con').slideUp()
    
    								if ($(this).hasClass('menu_li_active')) {
    									$(this).removeClass('menu_li_active')
    								} else {
    									$(this).addClass('menu_li_active').siblings().removeClass('menu_li_active')
    								}
    							})
    						})
    					script>
    				ul>
    			div>
    		header>
    
    		<script>
    			$(function() {
    				$(".l-toggle").on('click', function() {
    					var _this = $(this);
    					if (!$(this).hasClass('hover')) {
    						$(this).addClass('hover');
    						$(this).children('.line2').stop(true, true).fadeOut(300);
    						$(this).parents(".header-right").siblings('.sub-menu').stop().fadeIn();
    
    
    					} else {
    						$(this).removeClass('hover');
    						$(".header").removeClass("active");
    						$(this).children('.line2').stop(true, true).fadeIn(300);
    						$(this).parents(".header-right").siblings('.sub-menu').stop().fadeOut();
    
    					}
    				});
    			})
    		script>
    	body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309

    完成~

  • 相关阅读:
    【字符编码】c++编码格式及转换
    动作捕捉系统用于地下隧道移动机器人定位与建图
    【今日文章】:1.关于 $attr $lisenner $slot 用法的思考 2. 关于父子组件传值的思考 3.关于前端日志系统搭建的思考
    基础设施即代码(IAC),Zalando Postgres Operator UI 入门
    ICPC 2019-2020 North-Western Russia Regional Contest | JorbanS
    Spring 中 Bean 的作用域和生命周期
    李宏毅-21-hw3:对11种食物进行分类-CNN
    超声波模块详细介绍(stm32循迹小车中超声波的介绍)
    LeetCode 22. Generate Parentheses
    OAuth2:微服务权限校验Session共享
  • 原文地址:https://blog.csdn.net/weixin_48596030/article/details/134463799