Powered by md-Blog  文 - 篇  访客 -

基于jQuery的鼠标指上两端推出下划线的效果


更新:2020-03-12 16:31:34  /  创建:2020-03-12 16:18:41  /  分类:写一个Demo  / 
不要删除

1、先看效果

img

2、源码奉上

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo</title>
    <style>
        .n_txt {
            font-size: 16px;
            float: left;
            margin: 6px;
            height: 20px;
            position: relative;
            color: #2a2a2a;
            cursor: pointer;
        }
        .nav_hover {
            left: 50%;
            position: absolute;
            width: 0%;
            height: 2px !important;
            background: #F00;
            margin-top: 4px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="n_item">
        <div class="n_txt">首页
            <div class="nav_hover"></div>
        </div>
    </div>
    <div class="n_item">
        <div class="n_txt">手机平板
            <div class="nav_hover"></div>
        </div>
    </div>
    <div class="n_item">
        <div class="n_txt">笔记本/台式机
            <div class="nav_hover"></div>
        </div>
    </div>
    <div class="n_item">
        <div class="n_txt">打火机
            <div class="nav_hover"></div>
        </div>
    </div>
</body>

</html>

<script src="http://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
    crossorigin="anonymous"></script>
<script>
    $(document).ready(function () {
        $('.n_item').hover(function () {
            $(this).find('.nav_hover').stop().animate({ 'width': '100%', 'marginLeft': '-50%' }, 200)
        }, function () {
            $('.nav_hover').stop().animate({ 'width': '0', 'marginLeft': '0' }, 200);
        })
    })
</script>
不要删除

小站不易,感谢支持!