鼠标经过缩近

<!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>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #ccc;
        }

        .box {
            width: 700px;
            height: 300px;
            background-color: #fff;
            margin: 100px auto;
            padding: 20px;
        }

        .box ul {
            list-style: none;
            display: flex;
            flex-wrap: wrap;
        }

        .box ul li {
            box-sizing: border-box;
            position: relative;
            border: 1px solid #ccc;
            width: 350px;
            height: 150px;

        }

        .box ul li a {
            color: #000;
        }


        .box ul li img {
            position: absolute;
            left: 20px;
            top: 20px;
            transition: all 1s;
        }

        .box ul li p {
            position: absolute;
            right: 20px;
            top: 60px;
            transition: all 1s;
        }

        .box li.active {
            border-color: aqua;
        }

        .box li.active img {
            left: 60px;
        }

        .box li.active p {
            right: 50px;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li >
                <a href="#">
                    <img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
                    <p>学科介绍</p>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
                    <p>就业前景</p>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
                    <p>课程大纲</p>
                </a>
            </li>
            <li>
                <a href="#">
                    <img src="https://img0.baidu.com/it/u=2892901746,3942342212&fm=253&fmt=auto&app=138&f=PNG?w=126&h=129" alt="">
                    <p>师资介绍</p>
                </a>
            </li>
        </ul>
    </div>
<script>
    // 1.获取所有的li标签
    const lis = document.querySelectorAll('.box ul li')
    // 2.设置鼠标经过的状态
    for(let i=0;i<lis.length;i++){
        lis[i].addEventListener('mouseenter',function(){
            lis[i].classList.remove('active')
            lis[i].classList.add('active')
        })
        // 3.设置鼠标移出的状态
        lis[i].addEventListener('mouseleave',function(){
            lis[i].classList.remove('active')
            
        })
    }
    // 3.设置鼠标移出的状态
</script>
  
</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值