2021-08-02

js实现鼠标移动上出现移出消失

通过js改变displa属性的值进行实现
onmouseover来进行添加 //鼠标移上时的操作
onmouseout来进行删除 //鼠标移下时的操作

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

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .nav {
            height: 41px;
            border-top: #ff8500 solid 3px;
            border-bottom: #edeef0 solid 1px;
            background-color: #fcfcfc;
            line-height: 41px;
            font-size: 12px;
        }
        a {
            text-decoration: none;
            display: inline-block;
            padding: 0 20px;
            height: 41px;
            color: #4c4c4c;
        }
        a:hover {
            color: #ff8500;
            background-color: #eee;
        }
        .my {
            height: 80px;
            width: 140px;
            background-color: #ff8500;
            display: none;
        }
    </style>
</head>

<body>
    <div class="nav">
        <a href="#" onmouseover="add()" onmouseout="delet()">新浪</a>
        <a href="#">新浪号</a>
        <a href="#">新浪很好</a>
        <a href="#">新浪非常好</a>
    </div>
    <div class="my" id="my">
        
    </div>
</body>
    <script>
        function add(){
        var a = document.getElementById("my")
        console.log(a)
        a.style.display = "block"
        }
        function delet(){
        var a = document.getElementById("my")
        console.log(a)
        a.style.display = "none"
        }

    </script>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值