下划线跟随导航

Original 2018-12-31 13:29:07 201
abstract:<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>下划线跟随导航</title> <script type="text/javascript" src="../jquery-3.3.1.js&quo

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

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

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

<style type="text/css">

*{

margin: 0;

padding: 0;

}

ul{

list-style: none;

font-size: 15px;

position: relative;

z-index: 20;

}

li{

float: left;

width: 100px;

height: 30px;

text-align: center;

cursor: pointer;

}

.menu{

width: 500px;

position: relative;

margin: 20px auto;

height: 32px;

box-shadow: 0 2px 20px;

background: #AF3434;

border-radius: 50px;

}

#block{

z-index: 10;

width: 100px;

height: 2px;

background: #FFFFFF;

position: absolute;

top: 30px;

}

</style>

<script type="text/javascript">

$(function () {

$('li').hover(

function () {

//获取移动变量

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

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

},

//初始化元素

function () {

$('#block').stop().animate({left:'0px'})

}

)

});

</script>

</head>

<body>

<div class="menu">

<ul>

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

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

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

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

</ul>

<div id="block"></div>

</div>


</body>

</html>


Correcting teacher:天蓬老师Correction time:2018-12-31 16:29:03
Teacher's summary:这个是考察简单的自定义动画, 动动手, 想想 还能实现哪些有意思的效果?

Release Notes

Popular Entries