JavaScript 案例之 手风琴特效(jQuery实现)

11 篇文章 0 订阅

今天学习了jQuery,突发奇想自己动手做一个手风琴特效,这个特效在开发过程中最困难的就是布局,至于jQuery特效的实现还是比较简单的。

话不多说,直接上代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        .container{
            width:1380px;
            height:350px;
            margin:100px auto;
            overflow: hidden;
        }
        .wrapper{
            width : 1400px;
        }
        .box{
            width : 345px;
            height : 350px;
            float: left;
            position: relative;
            overflow: hidden;
        }
        .box .title{
            width : 345px;
            height:350px;
            background-color : #ddd;
        }
        .box .content{
            position: absolute;
            top:0;
            left : 345px;
        }
    </style>
</head>
<body>
    <div class="container">
       <div class="wrapper">
            <div class="box">
                <div class="title" style="background-color:yellowgreen"></div>
                <div class="content"><img src="https://img.zcool.cn/community/0150da5e8699fba80120a895bbc205.jpg@1380w" alt=""></div>
            </div>
            <div class="box">
                <div class="title" style="background-color:skyblue"></div>
                <div class="content"><img src="https://img.zcool.cn/community/0110175e8406a3a8012165180cde75.png@1380w" alt=""></div>
            </div>
            <div class="box">
                <div class="title" style="background-color:#ddd"></div>
                <div class="content"><img src="https://img.zcool.cn/community/015a3c5e8406eaa80121651832107d.png@1380w" alt=""></div>
            </div>
            <div class="box">
                <div class="title" style="background-color:#f99"></div>
                <div class="content"><img src="https://img.zcool.cn/community/01a2675e840704a80120a8952b329a.png@1380w" alt=""></div>
            </div>
       </div>
    </div>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script>
        // 1. 让当前的盒子,宽度变成1380px; 让其与的盒子宽度变成0;
        // 2. 移出的时候让所有的盒子宽度变成345px;

        $(".box").mouseover(function(){
            $(this)
            .stop(true)
            .animate({
                width : 1380
            })
            .siblings(".box")
            .stop(true)
            .animate({
                width : 0
            })
            .end()
            .children(".content")
            .css({
                left : 0
            })
        })

        $(".box").mouseout(function(){
            $(".box")
            .stop(true)
            .animate({
                width : 345
            })
            .queue(function(){
                $(this)
                .children(".content")
                .css({
                    left : 345
                })
            })
        })
    </script>
</body>
</html>

感兴趣的小伙伴可以自己动手试一下啦。有什么更好的写法欢迎评论区留言。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值