【问题标题】:I want .tabcontent to appear from 0 center to full size animated over .3 seconds我希望 .tabcontent 从 0 中心显示到全尺寸动画超过 0.3 秒
【发布时间】:2016-05-19 00:35:48
【问题描述】:

Sample of hover effect

我希望悬停效果在 0.3 秒内从 0 中心向外变为全尺寸。效果是我想要的,但动画不起作用。我要构建的页面将包含八个不同的图像(两列四列)我希望这种悬停效果在您悬停每个图像时起作用。

#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-->

【问题讨论】:

    标签: css animation css-transitions


    【解决方案1】:

    只需从.tabcontent 中删除display: none;,因为此属性不能动画,只有数字属性可以动画。

    小提琴:

    https://jsfiddle.net/uxouomoy/

    【讨论】:

      【解决方案2】:

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

      fiddle

      这是它使用的 css:

      #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;
      }
      <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-->

      【讨论】:

        猜你喜欢
        • 2015-10-19
        • 2013-03-24
        • 2021-05-30
        • 1970-01-01
        • 2021-12-28
        • 2014-11-19
        • 2014-08-22
        • 1970-01-01
        • 2010-10-29
        相关资源
        最近更新 更多