【问题标题】:Check transition finish检查过渡完成
【发布时间】:2013-07-18 22:17:54
【问题描述】:

我有一个带过渡的 div。我只是通过一些放松来扩展它。悬停时会更改其background-color,当我们将鼠标移出时会再次更改其background-color!但我希望背景颜色在过渡完成后恢复。我该怎么做?

HTML:

<div class="userWidget">
    <div class="user">
        <img src="img/user.png" width="50" height="50" />   <span class="name">Danish</span>
        <br/>   <span class="skills">Coder, Programmer</span>

    </div>
</div>
<div class="userWidget">
    <div class="user">
        <img src="img/user.png" width="50" height="50" />   <span class="name">Danish</span>
        <br/>   <span class="skills">Coder, Programmer</span>

    </div>
</div>
<div class="userWidget">
    <div class="user">
        <img src="img/user.png" width="50" height="50" />   <span class="name">Danish</span>
        <br/>   <span class="skills">Coder, Programmer</span>

    </div>
</div>
<div class="userWidget">
    <div class="user">
        <img src="img/user.png" width="50" height="50" />   <span class="name">Danish</span>
        <br/>   <span class="skills">Coder, Programmer</span>

    </div>
</div>

CSS:

.userWidget {
    position: relative;
    display: inline-block;
    width: 250px;
    height: 50px;
    overflow: visible;
    z-index: 1;
}
.userWidget:hover {
    z-index: 2;
}
.user {
    position: absolute; 
    display: inline-block;
    width: 200px;
    height: 50px;
    margin-bottom: 5px;
    background: #fff;
    transition: width 0.3s, height 0.3s;
}
.user:hover {
    width: 350px;
    height: 200px;
    transition: width 0.3s ease 0.5s, height 0.3s ease 0.5s, background-color 2.3s;
    background: #eee;
}
.user img {
    float: left;
}
.user .name, .skills {
    margin-left: 5px;
}
.user .name {
    font-size: 21px;
    font-weight: bold;
}

这是fiddle

正如您在小提琴中看到的那样,返回过渡只会让它变得很奇怪!转换完成后如何将background-color 恢复为#fff

【问题讨论】:

    标签: html css


    【解决方案1】:

    使用关键帧动画而不是过渡效果会更好吗 (jsfiddle demo)?

    .user:hover {
        width: 350px;
        height: 200px;
        transition: width 0.3s ease 0.5s, height 0.3s ease 0.5s;
        animation: flash 2.5s ease .8s forwards;
    }
    
    @keyframes flash {
        0% { background: #fff; }
        80% { background: #eee; }
        100% { background: #fff; }
    }
    

    【讨论】:

    • 它不起作用,背景颜色从一开始就改变了! :(
    • 抱歉,我在“动画”语法中使用了错误的子属性顺序。请参阅编辑和更新示例:jsfiddle.net/PuCML/6
    • 仍然,我希望 #eee 在我们将鼠标悬停在 div 上时出现,并在 div 恢复到原始大小时消失!
    • 再次抱歉,看来我完全误解了任务:(可能您只需要为 .user 的转换值添加“背景”(非悬停):jsfiddle.net/PuCML/7?
    猜你喜欢
    • 2014-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 1970-01-01
    • 2013-06-30
    • 2013-05-21
    • 1970-01-01
    相关资源
    最近更新 更多