jq封装之手风琴

这篇博客详细介绍了如何使用jQuery进行封装,创建手风琴效果。通过HTML结构和jQuery代码的结合,实现了内容区域的展开与折叠,提供了一种优化网页空间利用的交互方式。

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

jquery封装部分

$.fn.acc = function (colors, width) {
    colors = colors || []
    width = width || 100;
    var $li = this.find("li");
    var maxlength = this.width() - width * ($li.length - 1);
    var avglength = this.width() / $li.length;

    $li.mouseenter(function () {
        $(this).stop().animate({width: maxlength}).siblings().stop().animate({width: width})
    })
    $li.mouseleave(function () {
        $li.stop().animate({width: avglength})
    })


}

html部分

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>

        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        div {
            width: 1200px;
            height: 400px;
            /*border: 2px solid #000;*/
            margin: 100px auto;
            overflow: hidden;
        }
        ul{
            width: 1220px;
        }

        li {
         Apx;
            float: left;
        }

    </style>
</head>
<body>

<div id="box">

    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>

</div>

<script src="js/jquery-1.12.4.js"></script>
<script src="js/jquery.acc.js"></script>
<script>


     $("#box li").each(function (index,ele) {
         $(ele).css("backgroundImage","url(images/"+(index+1)+".jpg)")
     })
     $("#box").acc();
   

</script>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值