麻烦老师帮忙检查下
来源:2-8 项目作业
一天吃五顿
2022-09-19 22:10:59
<!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;
}
nav {
width: 1200px;
height: 40px;
margin: 100px auto;
position: relative;
}
nav a {
float: right;
height: 40px;
width: 80px;
color: #fff;
border-radius: 5px;
line-height: 40px;
text-align: center;
background-color: #000;
font-size: 14px;
text-decoration: none;
}
ul {
list-style: none;
float: right;
}
nav h3 {
float: left;
font-weight: 400;
line-height: 40px;
}
nav ul li {
float: left;
width: 30px;
text-align: center;
font-size: 14px;
line-height: 40px;
margin-right: 30px;
cursor: pointer;
}
div {
position: absolute;
bottom: 0;
left: 820px;
height: 2px;
width: 30px;
background-color: #f01400;
transition: left .3s ease 0s;
}
.curren {
color: #f01400;
}
</style>
</head>
<body>
<nav>
<h3>慕课手机</h3>
<a href="javascript:;">立即购买</a>
<ul>
<li class="curren">首页</li>
<li>外观</li>
<li>配置</li>
<li>型号</li>
<li>说明</li>
</ul>
<!-- 下划线 -->
<div></div>
</nav>
<script>
var list = document.querySelector('ul');
var lis = list.querySelectorAll('li');
var div = document.querySelector('div');
list.addEventListener('mouseover', function (e) {
if (e.target.tagName.toLowerCase() == 'li') {
for (var i = 0; i < lis.length; i++) {
lis[i].className = '';
}
e.target.className = 'curren';
div.style.left = e.target.offsetLeft + 'px';
}
})
</script>
</body>
</html>
1回答
imooc_慕慕
2022-09-20
同学你好,代码效果正确,很棒,祝学习愉快~
相似问题