返回下划线跟随导航...登陆

下划线跟随导航

黄健2019-03-16 22:26:29238
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>下划线跟随导航条</title>
    <style type="text/css">
        *{padding: 0;margin: 0}
        .cont{height: 600px;width: 40px; margin:0 auto;position: relative}
        ul {
            list-style: none;
            font-size: 20px;
        }
        li{cursor: pointer;width: 100px;height: 40px;text-align: center;line-height: 40px;background-color: skyblue;box-shadow: 0px 2px 20px skyblue}
    </style>
</head>
<body>
<div class="cont">
    <ul>
        <li name="0">html</li>
        <li name="1">css</li>
        <li name="2">javascript</li>
        <li name="3">php</li>
        <li name="4">mysql</li>
    </ul>
    <div class="xian" style="width:2px;height: 40px;background-color: orange;position: absolute;top:0px"></div>
</div>
</body>
</html>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
    $(function () {
        $("li").hover(function () {
            $x = parseInt($(this).attr('name'))*40;
            $('.xian').stop().animate({'top':$x+'px'},300);
        },function () {
            $('.xian').stop().animate({'top':'0px'},300);
        })
    })
</script>

效果图:

navjq.gif


总结:为什么要先stop(); 因为hover离开的时候动画效果会回到最开始,不stop的话会出现来回滑动。

最新手记推荐

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

全部回复(0)我要回复

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