下拉菜单问题?

来源:7-2 作业题

慕田峪5398473

2019-04-28 20:17:52

<meta name="viewport" content="width=device-width,maximum-scale=1,minimum-scale=1,user-scalable=no">
	<link rel="stylesheet" type="text/css" href="css/index1.css">
	<script type="text/javascript" src="JS/jquery.js"></script>
	<script type="text/javascript" src="JS/script.js"></script>
	
</head>
<body>
<div class="box">
	<header>	
		<div class="header_top">
			<div class="top"><a>前端</a></div>
			<div class="top"><a>Java</a></div>
			<div class="top"><a>Adroid</a></div>
			<div class="top"><a>ios</a></div>
			<div class="top"><a>php</a></div>
		</div>
			<div class="imooc">
				<a href="#">imooc</a>
				<a href="#">□</a>
			</div>
		<div class="header_center">
			<img src="image/1.png">
			<span>IMOOC</span>
			<div>start</div>
		</div>
	</header>
	
	
	/*css*/
	@media screen and (min-width: 760px){
	.header_top{
	display: block;
	width: 100%;
	height: .8rem;
	box-sizing: border-box;
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	border: 1px red solid;
	}
	.header_top .top{
		padding: 0 .25rem;
		color: #757575;
	}
	.header_top .top:nth-child(1) a{
		color: #afafaf;
	}
	.imooc{
		display: none;
	}
}
@media screen and (max-width: 760px){
	.header_top{
		width: 100%;
		height: 2.5rem;
		background: #7EA6B1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		text-align: center;
		position:absolute;
		left:0;

		display: none;
	}

	.header_top .top:nth-child(1) a{
	color: #545454;
	}
	.header_top .top{
		width: 100%;
		height: .5rem;
		line-height: .5rem;
		border-bottom: 1px solid rgba(255,255,255,.4);
		box-sizing: border-box;
		background: #7EA6B1;
		transition: all 2s;
	}
	.imooc{
		display: block;
		width: 100%;
		height: 1rem;
		background: #7EA6B1;
		line-height: 1rem;
		font-size: .4rem;
	}
	.imooc a:first-child{
		display: block;
		height: 1rem;
		position: absolute;
		left: 45%;
		top: 0;
		color: rgba(255,255,255,.7);
		font-weight: bold;
	}
	.imooc a:last-child{
		color: rgba(255,255,255,.7);
		position: absolute;
		right: .3rem;
		top:0;
		cursor: pointer;
	}
}
/*重复部分*/
*{padding: 0;margin: 0}
a{
	text-decoration: none;
	color: #545454;
}
body{font-size: 12px;font-family:'宋体';}
.box{
	width: 7.68rem;
	margin: 0 auto;
	box-shadow: 0 0 1px #f0f0f0;
}
/*header*/
/*第一区域*/
header{
	width: 7.68rem;
	height: 5.5rem;
	background-color: #B2C5CC;
}
.header_center{
	width: 1.3rem;
	text-align: center;
	margin: .6rem auto;
}
.header_center img{
	width: 90%;
}
.header_center span{
	display: block;
	color: #fff;
	font-size: .2rem;
	margin: .25rem 0 .5rem 0;
}
.header_center div{
	width: 1.3rem;
	height: .35rem;
	line-height: .35rem;
	background: #fff;
	text-align: center;
	box-shadow: 0 0 1px #f2f4f6;
}

/*js*/
(function(document,windows){
	var docE1 = document.documentElement,
	resizeEvt = 'orientationchange' in window ? 'orientationchange':'resize',
	recalc = function(){
		var clientWidth = docE1.clientWidth;
		if(!clientWidth) return ;
		if(clientWidth >= 768){
			docE1.style.fontSize = '100px';
		}else{
			docE1.style.fontSize = (clientWidth/7.68) + 'px'
			
		}
	};
	if (!document.addEventListener) return;
	window.addEventListener(resizeEvt,recalc,false);
	document.addEventListener('DOMContentLoaded',recalc,false);
	recalc();
})(document,window);


$(document).ready(function(){
	var btn = $('.imooc a').eq(1),
	top = $('.header_top');
	btn.on('click',function(){

		if(top.css('display')=='none'){
			top.css({'display':'block'});
			top.css({'top':'1rem'});
		}
		else{
			top.css({'display':'none'});
		}
		
	});
});


写回答

2回答

好帮手慕星星

2019-04-29

同学你好,是因为下拉菜单的显示与隐藏设置的display属性,两个设备下用的是同一个导航,iPhone6下设置隐藏了,iPad设备下也就不会显示了。这样也没有问题,因为一般情况下两个设备是互不影响的。

如果想要iPad设备下也显示的话,可以设置在iPhone6设备下导航相对于顶部定位,改变定位的top值来达到显示与隐藏的效果,可以自己试一下。

祝学习愉快!

0

慕田峪5398473

提问者

2019-04-28

为什么在iphone6下点击下拉菜单后,在恢复ipad,最上面的导航栏就消失了?

0

0 学习 · 5012 问题

查看课程