返回重要在$x的理......登陆

重要在$x的理解和animate()动画效果的应用,最后初始化

古。。2018-11-21 00:10:20212

<!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">

*{padding:0;margin:0;}

.menu{

height: 40px;

    width: 300px;

    background:pink;  

    margin:0px auto;

    position: relative;

    top:20px;

}

ul li{

list-style: none;

float:left;

text-align: center;

width: 98px;

height: 38px;

line-height: 40px;

border: 1px solid #ccc;


}

.ha{width: 100px;height: 2px;background: blue;position: absolute;top:40px;}

</style>

<script type="text/javascript">

$(function(){

$('li').hover(function(){

$x=parseInt($(this).attr('name'))*100//最重要的一步获取x数

  $('.ha').stop().animate({left:$x+'px'},100)

},

function(){

$('.ha').stop().animate({left:'0px'},100)}

)

})

</script>

</head>

<body>

<div class="menu">

<ul>

<li name='0'>wo是红色</li>

<li name='1'>wo是蓝色</li>

<li name='2'>wo是黄色</li>

</ul>

<div class="ha"></div>

</div>

</body>

</html>


最新手记推荐

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

全部回复(0)我要回复

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