检查过渡完成

时间:2013-07-03 19:05:19

标签: html css html5 css3

我有一个带过渡的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

1 个答案:

答案 0 :(得分: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; }
}