如何使用CSS淡入新的HTML元素

时间:2014-04-14 11:22:40

标签: html css css-transitions

如果只使用CSS而不使用任何JavaScript,如何才能使所有新的HTML元素淡入?

1 个答案:

答案 0 :(得分:2)

您可以使用CSS过渡

以下是一些示例代码:

<style>
.swapMe img { -webkit-transition: all 1s ease-in-out; -moz-transition: all 1s ease-in-out; -ms-transition: all 1s ease-in-out; -o-transition: all 1s ease-in-out; transition: all 1s ease-in-out; } .swap1, .swapMe:hover .swap2 { -webkit-opacity: 1; -moz-opacity: 1; opacity: 1; } .swapMe:hover .swap1, .swap2 { -webkit-opacity: 0; -moz-opacity: 0; opacity: 0; }
</style>

<div class="swapMe">
  <img src="http://0.tqn.com/d/webdesign/1/0/D/m/1/jaryth1.jpg" class="swap1" style="position: absolute;">
  <img src="http://0.tqn.com/d/webdesign/1/0/E/m/1/jaryth2.jpg" class="swap2">
</div>