返回下划线跟随菜单......登陆

下划线跟随菜单作业

方山2019-02-18 13:22:24262

通过学习,理解了jQuery的hover()的灵活使用,本次作业利用a标签重新布局导航菜单,利用hover()实现下划线跟随效果。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>下划线跟随导航作业</title>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<!-- <script src="jquery-3.3.1.min.js"></script> -->
<style>
* {
padding: 0;
margin: 0;
}
a {
color: #fff;
text-decoration: none;
line-height: 40px;
}
.nav {
width: 100%;
background-color: hotpink;
position: relative;
}
.menu {
display: flex;
justify-content: space-between;
width: 1200px;
margin: 0 auto;
text-align: center;
}
.menu a {
width: 100px;
padding-right: 100px;
text-align: center;
position: relative;
}
.line {
position: relative;
left: 0px;
width: 100px;
border: 2px solid rgb(120, 28, 240);
}
</style>
</head>
<body>
<div class="nav">
<div class="menu">
<a href="" id='1'>公司简介</a>
<a href="" id='2'>公司荣誉</a>
<a href="" id='3'>服务项目</a>
<a href="" id='4'>技术支持</a>
<a href="" id='5'>人才招聘</a>
<a href="" id='6'>意见反馈</a>
</div>
<div class="line"></div>
</div>
<script>
$(function () {
$('.line').stop().animate({ left: '200px' }, 300);
$('a').hover(
function () {
$px = parseInt($(this).attr('id')) * 200
$('.line').stop().animate({ left: $px + 'px' }, 300)
},
function () {
$('.line').stop().animate({ left: '200px' }, 300)
}
)
})
</script>
</body>
</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送