学习笔记 - jQuery - 手风琴案例

本文介绍了一种使用jQuery实现的鼠标悬停效果,当鼠标移过列表项时,该列表项会扩展并显示额外的内容,而其他列表项则收缩并隐藏详细内容。此效果适用于导航菜单或展示列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

案例分析

♥.鼠标经过某个小li 有两步操作

        1.当前小li 宽度变为 224px, 同时里面的小div淡出,大div淡入

        2.其余兄弟小li宽度变为69px, 小div淡入, 大div淡出

效果展示

完整代码 

<!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>
    <script src="jquery.min.js"></script>
    <style>
        body {
            background-color: #ccc;
            font-size: 20px;
            margin: 100px;
        }

        * {
            margin: 0;
            padding: 0;
        }
        
        
        li {
            list-style-type: none;
        }
        
        .box {
            height: 69px;
            background-color: bisque;
            overflow: hidden;
        }
        .box li {
            position: relative;
            float: left;
            width: 69px;
            height: 69px;
            margin-right: 20px;
        }
        li.current {
            width: 224px;
        }
        li.current .small {
            display: none;
        }
        li.current .big {
            display: block;
        }
        a .small {
            position: absolute;
            top: 0;
            height: 0;
            width: 69px;
            height: 69px;
        }
        a .big {
            width: 224px;
            height: 69px;
            display: none;
        }

    </style>
</head>
<body>
    <script>
        $(function() {
            // 鼠标经过某个小li 有两步操作:
            $(".box li").mouseover(function() {
                // 1.当前小li 宽度变为 224px, 同时里面的小div淡出,大div淡入
                $(this).stop().animate({
                    width: 224
                }).find(".small").stop().fadeOut().siblings(".big").stop().fadeIn();
                // 2.其余兄弟小li宽度变为69px, 小div淡入, 大div淡出
                $(this).siblings().stop().animate({
                    width: 69
                }).find(".small").stop().fadeIn().siblings(".big").fadeOut();
            });
        });
    </script>
    
    <div class="box">
        <ul>
            <li class="current">
                <a href="javascript:;">
                    <div class="small" style="background-color: pink;"></div>
                    <div class="big" style="background-color: red;"></div>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <div class="small" style="background-color: pink;"></div>
                    <div class="big" style="background-color: blue;"></div>
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    <div class="small" style="background-color: pink;"></div>
                    <div class="big" style="background-color: orange;"></div>
                </a>
            </li>
        </ul>
    </div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值