下滑线跟随导航

原创 2019-02-23 10:11:27 283
摘要:<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>下滑线跟随导航</title> <script type="text/javascript" src="../jquery-3.3.1.min.js&quo

05(H1RK_4ZTW1`RH]WY%7ML.png


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>下滑线跟随导航</title>

<script type="text/javascript" src="../jquery-3.3.1.min.js"></script>

<style type="text/css">

*{margin: 0px;padding: 0px}

.menu{width: 500px;height: 35px;margin: 25px auto;background-color:#00a0e9;border-radius: 6px;position: relative;}

ul{list-style:none;font-size: 16px}

li{float: left;width: 100px;height: 30px;text-align: center;line-height: 35px;color: #fff;position: relative;cursor: pointer;}

li:hover{color: pink}

</style>


<script type="text/javascript">

$(function(){

$('li').hover(

function(){

$x=parseInt($(this).attr('name'))*100

$('.block').stop().animate({left:$x+'px'},300)

},

function(){

$('.block').stop().animate({left:'px'},300)

})

})

</script>

</head>


<body>

<div class="menu">

<ul>

<li name="0">首页</li>

<li name="1">视频教材</li>

<li name="2">社区问答</li>

<li name="3">技术文章</li>

<li name="4">资源下载</li>

</ul>

<div class="block" style="z-index: 10;width: 100px;height: 3px;background-color: #ff6700;position: absolute;top:32px"></div>

</div>


</body>

</html>


批改老师:天蓬老师批改时间:2019-02-23 10:28:50
老师总结:实现这种效果的方式不仅一种, jQuery无疑是最简单的

发布手记

热门词条