我想.tabcontent从0中心到全尺寸显示动画超过.3秒

时间:2016-05-18 14:49:04

标签: css3 animation css-transitions

Sample of hover effect

我希望悬停效果从0中心开始动画到超过0.3秒的完整大小。效果是我想要的,但是动画不起作用。我要构建的页面将包含八个不同的图像(每列两列四个)我希望这个悬停效果能够在你将鼠标悬停在每个图像上时起作用。

#tabbox{
	height: 300px;
	position: relative;
	//border: 2px solid #888;
}

#tabbox img{
	cursor: pointer;
	display: block;
	width: 240px;
	height: 240px;
}

.tab {
	float: left;
}

.tabcontent{
	position: absolute;
	padding:10px;
	top:0;
	width: 0px;
	height: 0px;
	background:rgba(0, 0, 0, .5);
	border:1px solid #fff;
	margin:10px;
	color:#fff;
	display:none;
	overflow:hidden;
	-webkit-transition: height 0.3s ease-in-out;
	-moz-transition: height 0.3s ease-in-out;
	-o-transition: height 0.3s ease-in-out;
	transition: height 0.3s ease-in-out;
}

.tabcontent:before{
	content: "";
	position: absolute;
	z-index: -1;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	-webkit-transform: scale(0);
	transform: scale(0);
	-webkit-transition-property: transform;
	transition-property: transform;
	-webkit-transition-duration: 0.3s;
	transition-duration: 0.3s;
	-webkit-transition-timing-function: ease-out;
	transition-timing-function: ease-out;
}

.tab:hover > .tabcontent{
	display: block;
	width: 200px;
	height: 200px;
}

.tab:hover:before, .tab:active:before{
	-webkit-transform: scale(1);
	transform: scale(1);
}
<div id="tabbox">
	<div class="tab">
		<img src="http://zone1.gingermartinco.netdna-cdn.com/wp-content/uploads/2012/04/Napa-Real-Estate-Realtor.jpg" />
		<div class="tabcontent">
			<p>Text box to describe the images around when you hover over them, this description will change depending on what image you hover over.</p>
		</div><!--tabcontent-->
	</div><!--tab-->
</div><!--tabbox-->

2 个答案:

答案 0 :(得分:1)

只需从display: none;移除.tabcontent,因为此属性无法设置动画,只能为数字属性设置动画。

小提琴:

https://jsfiddle.net/uxouomoy/

答案 1 :(得分:0)

你的小提琴和你的问题代码是不一样的。 但是,从小提琴中获取代码,您应该仅以.tabcontent样式进行转换。使用顶部和左侧属性从中心位置到左角位置进行动画处理。

请参阅fiddle

这是它正在使用的CSS:

&#13;
&#13;
#tabbox {
  height: 300px;
  position: relative;
  //border: 2px solid #888;

}
#tabbox img {
  cursor: pointer;
  display: block;
  width: 240px;
  height: 240px;
}
.tab {
  float: left;
}
.tabcontent {
  position: absolute;
  padding: 10px;
  width: 0px;
  height: 0px;
  background: rgba(0, 0, 0, .5);
  border: 1px solid #fff;
  margin: 10px;
  color: #fff;
  display: block;
  overflow: hidden;
  top: 100px;
  left: 100px;
  visibility: hidden;
  transition-timing-function: ease-in-out;
  transition-duration: 0.3s;
  transition: width top left;
}
.tab:hover > .tabcontent {
  visibility: visible;
  width: 200px;
  height: 200px;
  top: 0px;
  left: 0px;
}
&#13;
<div id="tabbox">
  <div class="tab">
    <img src="http://zone1.gingermartinco.netdna-cdn.com/wp-content/uploads/2012/04/Napa-Real-Estate-Realtor.jpg" />
    <div class="tabcontent">
      <p>Text box to describe the images around when you hover over them, this description will change depending on what image you hover over.</p>

    </div>
    <!--tabcontent-->
  </div>
  <!--tab-->


</div>
<!--tabbox-->
&#13;
&#13;
&#13;