CSS3 mouseout转换未按预期工作

时间:2017-04-20 21:26:46

标签: css css3 css-transitions transform

我有一些CSS3悬停效果来动画图片标题:

.imageDetails {
    width: 100%;
    height: 360px;
    position: absolute;
    bottom: -100px;
    opacity: 0;
    color: white;
    background-color: black;
}

.item:hover .imageDetails {
    bottom: 0;
    -webkit-transition: all 0.5s, -webkit-transform 0.5s;
    transition: all 0.5s, transform 0.5s;
    width:100%;
    height: 330px;
    opacity:1;
}

.readMoreLink {
    color:#ACACAC;
    opacity: 0; 
    text-align: center;
}

.item:hover .readMoreLink {
    -webkit-transition-duration: 2s; /* Safari */
    -webkit-transition-delay: 1s; /* Safari */
    transition-duration: 2s;
    transition-delay: 1s;
    opacity: 1;
}

hover上它会有效,但鼠标输出只是清除。我也希望它能滑出来。

我尝试使用以下内容,但行为不端。

.item:hover .imageDetails:not( :hover ){
    bottom: -100px;
    -webkit-transition: all 0.5s, -webkit-transform 0.5s;
    transition: all 0.5s, transform 0.5s;
    width:100%;
    height: 330px;
    opacity:1;
}

我可以使用CSS添加幻灯片效果还是jQuery更适合这类事情?

1 个答案:

答案 0 :(得分:2)

您还需要将过渡属性应用于非悬停类,如下所示:

.readMoreLink {
  color:#ACACAC;
  opacity: 0; 
  text-align: center;
  -webkit-transition-duration: 2s; /* Safari */
  -webkit-transition-delay: 1s; /* Safari */
  transition-duration: 2s;
  transition-delay: 1s;
}

.item:hover .readMoreLink {
  -webkit-transition-duration: 2s; /* Safari */
  -webkit-transition-delay: 1s; /* Safari */
  transition-duration: 2s;
  transition-delay: 1s;
  opacity: 1;
}

见这里:https://jsfiddle.net/bLmw0xzu/