请老师检查作业♥
来源:2-8 项目作业
xcn_aaaa
2022-09-30 10:06:02
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
a {
text-decoration: none;
}
.center-wrap {
width: 1200px;
margin: 0 auto;
}
.top {
height: 60px;
line-height: 60px;
}
.logo {
float: left;
}
.logo h1 {
font-size: 20px;
font-weight: normal;
}
.logo h1 a {
color: #000;
}
.nav {
float: right;
position: relative;
}
.nav ul {
float: left;
}
.nav ul li {
float: left;
margin-right: 25px;
color: #000;
font-size: 14px;
}
.nav .btn {
float: left;
width: 100px;
height: 35px;
background-color: #000;
color: #fff;
margin-top: 12px;
line-height: 35px;
font-size: 14px;
text-align: center;
border-radius: 4px;
}
.line {
position: absolute;
width: 30px;
height: 3px;
background-color: #f01400;
top: 45px;
left: 0;
transition: left .3s ease 0s;
}
.nav ul .current{
color: #f01400
}
</style>
</head>
<body>
<div class="top">
<div class="center-wrap">
<div class="logo">
<h1><a href="javascript:;">小慕手机</a></h1>
</div>
<div class="nav">
<ul id = "nav-ul">
<li class="current">首页</li>
<li>外观</li>
<li>配置</li>
<li>型号</li>
<li>说明</li>
</ul>
<a href="javascript:;" class="btn">立即购买
</a>
<div class="line" id = "line"></div>
</div>
</div>
</div>
<script>
var navUl = document.getElementById('nav-ul');
var lis = navUl.getElementsByTagName('li');
var line = document.getElementById('line');
navUl.onmouseover = function(e){
if(e.target.tagName.toLowerCase() == 'li'){
// 排他操作
for(var i = 0;i<lis.length;i++){
lis[i].className = '';
if(e.target == lis[i]){
line.style.left = i * 53 + 'px';
}
}
e.target.className = 'current';
}
}
</script>
</body>
</html>1回答
同学你好,代码实现效果很棒。继续加油,祝学习愉快!
相似问题