我有一个图表,如果可能的话,我想使用CSS制作动画。我看待自己这样做的方式就是使用一个掩码,所以它从零开始,然后慢慢地掩模逐渐显露出图形线。
这不是我正在使用的图像,但会是类似的: http://jsfiddle.net/e50mnm2p/
所以想象一下,它什么都没有开始,然后从左边开始,它会逐渐显露出绿线,给人的印象是它被画出来了。有没有办法用面具做这个或有更好的选择吗?
<img src="http://www.freeimages.com/assets/183018/1830173156/graph-line-up-and-down-1-1131299-m.jpg" />
更新
这就是我最终做的事情: http://jsfiddle.net/e50mnm2p/5/
HTML
<div class="hgInner">
<img src="http://www.freeimages.com/assets/183018/1830173156/graph-line-up-and-down-1-1131299-m.jpg" />
</div>
CSS
.hgInner {
position: relative;
float: left;
height: 100%;
width: 955px;
overflow: hidden;
-webkit-animation: reveal 4s ease;
-webkit-animation-fill-mode: backwards;
}
@-webkit-keyframes reveal {
0% {width: 0px;}
100% { width: 100%;}
}
@keyframes reveal {
0% {width: 0px;}
100% { width: 100%;}
}
答案 0 :(得分:7)
你想要这样的东西吗? http://jsfiddle.net/e50mnm2p/3/
.reveal {
overflow:hidden;
position:relative;
display:inline-block;
}
.reveal:after {
content:" ";
position:absolute;
display:block;
top:0;
left:0;
width:100%;
height:100%;
background:#fff;
z-index:2;
transition: all 2s ease;
}
.reveal.show:after {
left:100%
}
答案 1 :(得分:1)
您可以使用伪元素隐藏实际元素。要显示元素,请为伪元素的transform属性设置动画(将其旋转90度)。
HTML:
<div id="parent">
<div id="child"></div>
</div>
CSS:
#parent {
overflow: hidden;
}
#child {
position: relative;
background-color: yellow;
}
/* Pseudo-element that hides the child */
#child::after {
content: '';
position: absolute;
width: 150%;
height: 150%;
background-color: blue;
top: 0;
left: 0;
bottom: 0;
transform: rotate(0deg);
transform-origin: 0px 0px;
transition: transform linear 0.7s;
}
#child.animated::after {
transform: rotate(90deg);
}
Javascript:
$("#reveal-button").on('click', function() {
$("#child").toggleClass('animated');
});
在我的博文中解释隐藏元素的第二种方法是:http://usefulangle.com/post/37/revealing-hidden-elements-by-css-animations