如何使用jQuery向bootstrap 4中的card

编程入门 行业动态 更新时间:2024-10-10 00:29:46

<a href=https://www.elefans.com/category/jswz/34/1771452.html style=如何使用jQuery向bootstrap 4中的card"/>

如何使用jQuery向bootstrap 4中的card

这是我的卡片的html代码:

<div class="row">
        <% pro.forEach(function(pros){ %>
        <div class="col-lg-3 col-md-4">
            <div class="card mb-4 shadow ">
                <img class="card-img-top " src="<%= pros.image %>">
                <div class="card-body p-2 m-3">
                    <h5 class="card-title"><%= pros.name %></h5>
                    <p class="card-text my-0"><%= pros.description %></p>


                </div>
            </div>
        </div>
        <% }) %>
    </div>

当鼠标悬停在card-body上时,我想向card-img-top添加向下滑动功能。我正在尝试使用jQuery,但无法正常工作。她是我尝试使用jQuery代码:

<script>
$(".card-img-top").click(function() {
  $(".card-body").slideUp();
});
</script>
回答如下:您的代码的问题是,当您运行循环来创建卡时,有许多card-body类的卡。另外,slideup()用于素材UI。这是您的问题的一种解决方案,您可以根据需要进行自定义。

.card-body { overflow-y: hidden; max-height: 500px; /* approximate max height choose whatever suits you*/ transition-property: all; transition-duration: .5s; transition-timing-function: cubic-bezier(0, 1, 0.5, 1); } .card-body.closed { max-height: 0; } $(document).on("click", ".card-img-top" , function() { $('.card-body').removeClass('closed'); $(this).closest('.card-body').addClass('closed'); });

更多推荐

如何使用jQuery向bootstrap 4中的card

本文发布于:2024-05-07 14:09:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1756612.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   jQuery   card   bootstrap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!