jquery - css + Jquery 为了实现这种重叠

标签 jquery html css styles

My jsFiddle

我有 3 个 parent ,其中将包含未定义数量的 child ,( parent 是 float 的) child 是相对的,方案如下所示:

-----Parent-----   ------Parent------  ----Parent----
|    Child     |   |     Child       | |   Child    |
|    Child     |   |     Child       | |   Child    |
|    Child     |   |     Child       | |   Child    |
|    Child     |   |     Child       | --------------
----------------   -------------------

鼠标悬停时,子项会调整到更大的高度,但我希望它们重叠,我不想扩展父项。

我的 CSS 是这样的:

    .parent{
    position:relative;
    float:left;
    width:296px;
    background-color:pink;
    margin-right:10px;
}

    .child{
        position:relative;
        height:60px;
        margin-bottom:10px;
        background-image:url("../images/theme_test.png");
    }

我尝试使用顶部,Y 位置但它不起作用,下面的 child 会掉下来。

最佳答案

给你:jsFiddle .

我已经使用 margin 更新了头寸并注意到两件事:

  1. 我必须更改 z-index 以便悬停的元素位于顶部
  2. 我为最后一个 child 创造了一种特殊待遇——让它长大而不是倒下,这样就不会让 parent 更长

这是 mouseenter 事件:

$('.child').mouseenter(function() {
        $(this).css('z-index',5);
        if($(this).is(':last-child')){ // check if this is the last child
            $(this).animate({
                height: "80px",
                'margin-top': "-20px" // grow upwards..
            }, 250 );
        }else{
           $(this).animate({
                height: "80px",
                'margin-bottom': "-10px" // grow down wards..
            }, 250 );
        }
    })

mouseout 恰恰相反。

关于jquery - css + Jquery 为了实现这种重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17384677/

相关文章:

jquery - show 从 Div 隐藏内容,默认先显示

javascript - 如何使用 ng-class 渲染这个 Angular 变量

html - 悬停在元素上时从上一个/下一个元素中删除样式

html - 将下拉项显示为导航项而不是弹出列表

javascript - 如何将 jquery 与我的 Node.js EJS 模板一起使用?

css - 如何更改特定 CSS 伪元素的属性?

javascript - 如何在 jQuery 中编辑 css 规则?

jquery - 制作一个 jQuery 文本 slider

所有 IE 版本中的 jQuery .load() 问题

css - 更新面板 Controller 显示问题