前端手风琴

js实现

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>手风琴</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
            vertical-align: top;
        }
        ul{
            width: 1150px;
            height: 320px;
            margin:100px auto;
        }
        li{
            width: 230px;
            height: 320px;
            overflow: hidden;
            float: left;
        }
    </style>
</head>
<body>
<div id="box">
    <ul>
        <li style="background-color: red"></li>
        <li style="background-color: blue"></li>
        <li style="background-color: skyblue"></li>
        <li style="background-color: greenyellow"></li>
        <li style="background-color: deeppink"></li>
    </ul>
</div>
<script>
    window.onload=function(){
        var box = document.getElementById('box')
        var allli= document.getElementsByTagName('li')
        for(var i=0;i<allli.length;i++){
            var li = allli[i]
            li.index = i
            li.onmouseenter=function(){
                    for(var j=0;j<allli.length;j++){
                        allli[j].style.width= 100+'px'
                    }
                    allli[this.index].style.width=720 + 'px'

            }
            li.onmouseout=function(){
                for(var j=0;j<allli.length;j++){
                    allli[j].style.width= 230+'px'
                }
            }
        }
    }
</script>

</body>
</html>

jq实现

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>手风琴</title>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
            vertical-align: top;
        }
        /*#box{*/
        /*    width: 1150px;*/
        /*    height: 320px;*/
        /*    margin:100px auto;*/
        /*}*/
        ul{
            width: 1150px;
            height: 320px;
            margin:100px auto;
        }
        li{
            width: 230px;
            height: 320px;
            overflow: hidden;
            float: left;
        }
    </style>
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="box">
    <ul>
        <li style="background-color: red"></li>
        <li style="background-color: blue"></li>
        <li style="background-color: skyblue"></li>
        <li style="background-color: greenyellow"></li>
        <li style="background-color: deeppink"></li>
    </ul>
</div>
<script>
    $(function(){
        $('li').mouseenter(function(){
            $(this).stop().animate({'width':720}).siblings().stop().animate({'width':100})
        })
        $("li").mouseleave(function(){
            $(this).stop().animate({"width":230}).siblings().stop().animate({"width":230})
        })
    })
</script>

</body>
</html>

vue实现手风琴特效

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        ul{
            /*width: 1000px;*/
            height: 500px;
            /*background-color: #00FFFF;*/
            margin:100px auto;
        }
        li{
            float: left;
            width: 200px;
            height: 500px;
            /*border:1px solid #ccc;*/
        }
        p{
          border: 1px solid #ccc;
        }
        .big{
            width: 700px;
        }
        .small{
            width:100px;
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<ul id="box" :style="ulwidth">
    <li v-for="(color,index) in lis" v-bind:style="color" @click="change(index)" v-bind:class="['',cur==index ? big : small]"></li>
</ul>

<script>
    new Vue({
        el:'#box',
        data:{
            lis:['background: red','background: blue','background: green','background: pink','background: skyblue','background:purple'],
            cur:0,
            big:"big",
            small:'small'
        },
        computed:{
            ulwidth:function(){
                return {'width':(this.lis.length)*200+'px'}
            }
        },
        methods:{
            change:function(index){
                this.cur = index
            }
        }

    })
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值