jq实现鼠标上移内容展开

在这里插入图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body,ul,li{
            margin: 0;
            padding: 0;
        }
        .wrapper{
            width: 100%;
            height: 400px;
            border: 2px solid;
            box-sizing: border-box;
        }
        .list{
            width: 100%;
            height: 100%;
            list-style: none;
            overflow: hidden;
        }
        .list>li{
            float: left;
            height: 100%;

        }
    </style>
</head>
<body>
<div class="wrapper">
    <ul class="list">
    </ul>
</div>

<script src="jQuery-3.3.1.js"></script>
<script>
    let colors = ["red","yellow","green", "cyan", "pink","hotpink", "blue", "yellowgreen","greenyellow", "skyblue"];
    colors.forEach(item => {
        $('.list').append(`<li style="background-color:${item}; width:${100 / colors.length}%"></li>`)
    }) ;
    $(document).on('mouseenter','.list>li',function () {
        let that = $(this);
        // that.animate({
        //    height: '50%'
        // }, 500)
        that.stop().animate({
            width:'100%'
        },500);
        that.siblings().stop().animate({
            width:'0'
        },500)
    });
    $(document).on('mouseleave','.list>li',function () {
        $('.list>li').stop().animate({
            width:100 / colors.length + '%'
        },500)
    })
</script>
</body>
</html>
发布了151 篇原创文章 · 获赞 1 · 访问量 2763

猜你喜欢

转载自blog.csdn.net/hql1024/article/details/103885467