代码之家  ›  专栏  ›  技术社区  ›  MauriceNino HarshitMadhav

悬停时更改变换状态

  •  0
  • MauriceNino HarshitMadhav  · 技术社区  · 8 年前

    所以我有一些像这样的css代码

        .some_class{
            width: 30%;
            height: 120px;
            margin-left: 10%;
            margin-right: 10%;
            margin-top: 100px;
            float: left;
            @include boxShadowLevel(2);
            transition: box-shadow 0.4s, transform 0.4s;
    
            transform: scale(0);
    
            &:nth-child(odd):hover{
                transform: translate(-3px, -3px) scale(1.1);
                @include boxShadowLevel(3);
            }
    
            &:nth-child(even):hover{
                transform: translate(3px, -3px) scale(1.1);
                @include boxShadowLevel(3);
            }
    
            // Some more css here (which is not relevant for the question)
    
        }
    

    正如您所看到的,标准转换是scale(0),这是因为我在加载一些js代码时淡入了它

    $(elem[i]).css("transform", "scale(1)")
    

    问题是悬停没有改变任何东西,我怀疑这是因为初始变换。

    没有第二个包装器div或类似的东西,有什么解决方案吗?

    1 回复  |  直到 8 年前
        1
  •  0
  •   MauriceNino HarshitMadhav    8 年前

    我自己找到了解决办法。 这是我的SCS(请注意添加的“show”)

    .some_class{
        width: 30%;
        height: 120px;
        margin-left: 10%;
        margin-right: 10%;
        margin-top: 100px;
        float: left;
        @include boxShadowLevel(2);
        transition: box-shadow 0.4s, transform 0.4s;
    
        transform: scale(0);
    
        &.show{
            transform: scale(1);
        }
    
        &:nth-child(odd):hover{
            transform: translate(-3px, -3px) scale(1.1);
            @include boxShadowLevel(3);
        }
    
        &:nth-child(even):hover{
            transform: translate(3px, -3px) scale(1.1);
            @include boxShadowLevel(3);
        }
    
        // Some more css here (which is not relevant for the question)
    
    }
    

    然后添加类“show”,而不是在js代码中手动设置转换:

    $(elem[i]).addClass("show")