css3过渡:firefox将鼠标悬停在外,并且将鼠标悬停在中

时间:2013-07-10 14:41:59

标签: css css3 google-chrome firefox transition

我希望两者都像webkit一样,但出于某些原因,webkit的工作方式与我预期的一样,但是-moz-在鼠标输出.porftolio项目时执行动画,

知道为什么吗?

CSS:

.portfolio-item {
  float: left;
  width: 300px;
  height: 300px;
  margin: 0.5%;
  position: relative;
  text-align: center;
  background: orange;
  overflow: hidden;
  -webkit-transition: 0.4s all ease;
  -moz-transition: 0.4s all ease;
  transition: 0.4s all ease;
}
.portfolio-item a:hover:after {
  content: " ";
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(255, 255, 255, 0.4), transparent 100%);
}
.portfolio-item h4, .portfolio-item img {
  -webkit-transition: 0.4s all ease;
  -moz-transition: 0.4s all ease;
  transition: 0.4s all ease;
}
.portfolio-item img {
  width: 100%;
  hegight: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.portfolio-item:before {
  content: '';
  display: -moz-inline-stack;
  display: inline-block;
  vertical-align: middle;
  *vertical-align: auto;
  zoom: 1;
  *display: inline;
  height: 100%;
  vertical-align: middle;
}
.portfolio-item h4 {
  opacity: 0;
  color: white;
  font-size: 30px;
  vertical-align: middle;
  /*@include transform(scale(.5));*/
  display: -moz-inline-stack;
  display: inline-block;
  vertical-align: middle;
  *vertical-align: auto;
  zoom: 1;
  *display: inline;
  /* sino en safari no va */
  width: 200px;
  font-weight: bold;
  text-transform: uppercase;
  -webkit-transform: translateX(-2px);
  -moz-transform: translateX(-2px);
  -ms-transform: translateX(-2px);
  transform: translateX(-2px);
}
.portfolio-item:hover {
  z-index: 9;
}
.portfolio-item:hover img {
  opacity: 0;
  -webkit-transform: scale(1.07);
  -moz-transform: scale(1.07);
  -ms-transform: scale(1.07);
  transform: scale(1.07);
}
.portfolio-item:hover h4 {
  -webkit-transform: translateX(3px);
  -moz-transform: translateX(3px);
  -ms-transform: translateX(3px);
  transform: translateX(3px);
  /*-webkit-animation-duration: 0.4s;
  -webkit-transform-origin:50% 50%;
  -webkit-animation-timing-function: linear;
  -moz-animation-duration: 0.4s;
  -moz-transform-origin:50% 50%;
  -moz-animation-timing-function: linear;
  -webkit-animation-name: shake;
  -moz-animation-name: shake;
  -o-animation-name: shake;
  animation-name: shake;*/
  opacity: 1;
}

HTML:

<ul><li class="portfolio-item"  style="background-color: #6220E5;">
                                <a href="#">
                                    <img src="http://dummyimage.com/300x300/dddddd/cccccc" alt="camper" />
                                    <h4>Text goes here</h4>
                                </a>
</li></ul>

测试: http://jsfiddle.net/kuX39/

- 编辑 -

有趣的是,我注意到如果不是将其应用于:hover我将它应用于.hover并切换类,那么动画的工作原理相同......:S

1 个答案:

答案 0 :(得分:1)

问题来自这条规则:

.portfolio-item a:hover:after {
  content: " ";
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(255, 255, 255, 0.4), transparent 100%);
}

只在悬停状态下定义所有后伪元素。如果a元素没有悬停,则伪元素是未定义的,并且可以采用浏览器决定的任何值。

如果你在非悬停元素上设置相同,它可以正常工作。

.portfolio-item a:after {
  content: " ";
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(rgba(255, 255, 255, 0.4), transparent 100%);
}

updated demo

顺便说一下,我的firefox版本正在使用转换而不是moz-transition