css+js 图片展示(vue)

 

html:

<template>
    <div class="content">
        <div class="container">
            <div class="panel " @click="btn_user($event)" style="background-image: url('https://images.unsplash.com/photo-1558979158-65a1eaa08691?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
                <h3>Explore The World</h3>
            </div>
            <div class="panel active" @click="btn_user($event)" style="background-image: url('https://images.unsplash.com/photo-1572276596237-5db2c3e16c5d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
                <h3>Wild Forest</h3>
            </div>
            <div class="panel" @click="btn_user($event)" style="background-image: url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1353&q=80')">
                <h3>Sunny Beach</h3>
            </div>
            <div class="panel" @click="btn_user($event)" style="background-image: url('https://images.unsplash.com/photo-1551009175-8a68da93d5f9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1351&q=80')">
                <h3>City on Winter</h3>
            </div>
            <div class="panel" @click="btn_user($event)" style="background-image: url('https://images.unsplash.com/photo-1549880338-65ddcdfd017b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80')">
                <h3>Mountains - Clouds</h3>
            </div>
        </div>
    </div>
</template>

css:

* {
        box-sizing: border-box;
    }

    body {
        font-family: 'Muli', sans-serif;
        display: flex;
        align-items: center;
        justify-content: center;
        height: 100vh;
        overflow: hidden;
        margin: 0;
    }
    .content{
        display: flex;
        width: 100vw;
        height: 100vh;
        justify-content: center;
        align-items: center;
    }
    .container {
        display: flex;
        width: 80vw;
        height: 100vh;
        justify-content: center;
        align-items: center;
    }
    .panel {
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        height: 80vh;
        border-radius: 50px;
        color: #fff;
        cursor: pointer;
        flex: 0.5;
        margin: 10px;
        position: relative;
        -webkit-transition: all 700ms ease-in;
    }

    .panel h3 {
        font-size: 24px;
        position: absolute;
        bottom: 20px;
        left: 20px;
        margin: 0;
        opacity: 0;
    }

    .panel.active {
        flex: 5;
    }

    .panel.active h3 {
        opacity: 1;
        transition: opacity 0.3s ease-in 0.4s;
    }

    @media (max-width: 480px) {
        .container {
            width: 100vw;
        }

        .panel:nth-of-type(4),
        .panel:nth-of-type(5) {
            display: none;
        }
    }

js:

methods:{
            btn_user(e){
                // console.log(document.getElementsByClassName("panel")[0].className)
                for (var i=0;i<5;i++){
                    if(document.getElementsByClassName("panel")[i].className=="panel active")
                    document.getElementsByClassName("panel")[i].className="panel"
                }
                // console.log(e.path[0].className)
                e.path[0].className="panel active"
            }
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

稻草人想看远方

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值