首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从卡片列表中一次只滑出一个卡片盒?

如何从卡片列表中一次只滑出一个卡片盒?
EN

Stack Overflow用户
提问于 2021-01-11 22:14:05
回答 1查看 31关注 0票数 0

这是我的网站的代码,看起来像这样:

我的CSS看起来像这样:

代码语言:javascript
复制
/** Card View ***/
.list-items {
    display: flex;
    flex-flow: wrap;
    justify-content: center;
}
.list-items .card{
    width: 18%;
    margin: 10px;
    background: #262626;

    position: relative;
    display: block;
    box-shadow: 0px 1px 2px 0px rgba(0,0,0,0.15);
    transition: 0.4s linear;
}
.card:hover{
    box-shadow: 0px 1px 35px 0px rgba(0,0,0,0.3);
}
.card .image{
    background: black;
    overflow: hidden;
}
.card .image img{
    height: 100%;
    width: 100%;
    transition: 0.3s;
}
.card.active .image img{
    opacity: 0.6;
    transform: scale(1.1);
}
.card .content{
    position: absolute;
    border: none;
    bottom: 0px;
    background: #262626;
    width: 100%;
    padding: 10px;
}
.content .title{
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
}
.content .category{
    color: #04e0b2;
    font-size: 12px;
}
.content .bottom{
    margin-top: 5px;
}
.content .bottom button{
    width: 100%;
    border: none;
    background: #04e0b2;
    color: #ffffff;
    font-weight: 800;
    padding: 8px 0px;
    transition: 0.3s ease;
    cursor: pointer;
}
.content .bottom button:hover{
    transform: scale(0.9);
}
.content .bottom{
    display: none;
}

这是HTML

代码语言:javascript
复制
<div class="list-items">
    <div class="card">
        <div class="image">
            <img src="https://www.themoviedb.org/t/p/w220_and_h330_face/mMWLGu9pFymqipN8yvISHsAaj72.jpg">
        </div>
        <div class="content">
            <div class="title">Dory's Reef Cam</div>
            <div class="category">Family, Animation, Comedy, Adventure</div>
            <div class="bottom">
                <button>Play</button>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="image">
            <img src="https://www.themoviedb.org/t/p/w220_and_h330_face/mMWLGu9pFymqipN8yvISHsAaj72.jpg">
        </div>
        <div class="content">
            <div class="title">Dory's Reef Cam</div>
            <div class="category">Family, Animation, Comedy, Adventure</div>
            <div class="bottom">
                <button>Play</button>
            </div>
        </div>
    </div>
</div>

Javascript如下所示:

代码语言:javascript
复制
//Card Hover
$('.card').hover(function(){
    if($(this).hasClass('active')){
        $('.card .bottom').slideUp(function(){
            $('.card').removeClass('active');
        });
    }else{
        $('.card').addClass('active');
        $('.card .bottom').stop().slideDown();
    }
});

它的幻灯片上所有的卡片,列表项目,所有的一次,我想知道如何实现它的单一项目一次!

有没有办法像这样悬停单项和它的滑块,但只针对单项!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-11 22:18:35

使用this引用悬停的卡

代码语言:javascript
复制
//Card Hover
$('.card').hover(function(){
$(this).toggleClass('active');
        $(this).find('.bottom').slideToggle();
});
代码语言:javascript
复制
/** Card View ***/
.list-items {
    display: flex;
    flex-flow: wrap;
    justify-content: center;
}
.list-items .card{
    width: 18%;
    margin: 10px;
    background: #262626;

    position: relative;
    display: block;
    box-shadow: 0px 1px 2px 0px rgba(0,0,0,0.15);
    transition: 0.4s linear;
}
.card:hover{
    box-shadow: 0px 1px 35px 0px rgba(0,0,0,0.3);
}
.card .image{
    background: black;
    overflow: hidden;
}
.card .image img{
    height: 100%;
    width: 100%;
    transition: 0.3s;
}
.card.active .image img{
    opacity: 0.6;
    transform: scale(1.1);
}
.card .content{
    position: absolute;
    border: none;
    bottom: 0px;
    background: #262626;
    width: 100%;
    padding: 10px;
}
.content .title{
    font-size: 18px;
    font-weight: 600;
    color: #ffffff;
}
.content .category{
    color: #04e0b2;
    font-size: 12px;
}
.content .bottom{
    margin-top: 5px;
}
.content .bottom button{
    width: 100%;
    border: none;
    background: #04e0b2;
    color: #ffffff;
    font-weight: 800;
    padding: 8px 0px;
    transition: 0.3s ease;
    cursor: pointer;
}
.content .bottom button:hover{
    transform: scale(0.9);
}
.content .bottom{
    display: none;
}
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="list-items">
    <div class="card">
        <div class="image">
            <img src="https://www.themoviedb.org/t/p/w220_and_h330_face/mMWLGu9pFymqipN8yvISHsAaj72.jpg">
        </div>
        <div class="content">
            <div class="title">Dory's Reef Cam</div>
            <div class="category">Family, Animation, Comedy, Adventure</div>
            <div class="bottom">
                <button>Play</button>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="image">
            <img src="https://www.themoviedb.org/t/p/w220_and_h330_face/mMWLGu9pFymqipN8yvISHsAaj72.jpg">
        </div>
        <div class="content">
            <div class="title">Dory's Reef Cam</div>
            <div class="category">Family, Animation, Comedy, Adventure</div>
            <div class="bottom">
                <button>Play</button>
            </div>
        </div>
    </div>
</div>

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65668474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档