今天我们要实验动画和过渡伪元素(前和后),我们要发现自己的潜能。我们将讨论一些关于动画伪元素,并看看在四个例子,使用一些特殊的技术来实现各种效果。
让我们先来看看在优点和缺点,一起前来与伪元素一起使用的动画和过渡。
优点
简化和优化的HTML标记
以CSS3能力的优势
促进设计
缺点
仅支持现代的浏览器,如火狐,IE10和Chrome
不工作的移动浏览器
伪元素无法ID所标识的
伪元素不会出现在DOM。
伪元素不能用JavaScript动画
很显然,有弊多利少,但我认为,我们应该对未来感到兴奋,并给它一个尝试!
下列四个例子创建了这个特定的主题。很显然,还有其他的方法达到相
很显然,有弊多利少,但我认为,我们应该对未来感到兴奋,并给它一个尝试!
下列四个例子创建了这个特定的主题。很显然,还有其他的方法达到相同的视觉效果,但为了这个实验,当然,我们会使用伪元素,所以要注意,它只能在浏览器支持自己的动画和过渡。
使用步骤
实例1
首先,我们要做的一个有趣的事情:动画一滴水落入一个圆形的容器(基于Codrops标志)
标记
<div class="drop"> </ DIV>
CSS
*,
*:before,
*:after {
box-sizing: border-box;
}
.drop {
background: rgba(255, 255, 245, 1);
border: 4px solid rgba(255, 245, 235, 1);
border-radius: 100%;
box-shadow: inset -0.1em 0 2em 0.5em rgba(255, 255, 255, 0.5),
inset -0.1em 0 0.5em 0 rgba(0, 0, 0, 0.8);
position: relative;
margin: 0 auto;
width: 15em;
height: 15em;
overflow: hidden;
}
.drop:before,
.drop:after {
content:"";
display:block;
position:absolute;
}
/* Drop */
.drop:before {
background: rgba(167, 217, 234, 1);
border-radius: 100%;
/* Drop start */
box-shadow: 0 0 0 0.1em rgba(167, 217, 234, 0.8),
0 0 0 0.15em rgba(167, 217, 234, 0.8),
0 0 0 0.2em rgba(167, 227, 234, 0.8),
0 0 0 0.25em rgba(167, 227, 234, 0.8),
0 0 0 0.3em rgba(167, 227, 234, 0.8),
0 0 0 0.35em rgba(167, 227, 234, 0.8),
0 0 0 0.4em rgba(167, 227, 234, 0.8),
0 0 0 0.45em rgba(167, 227, 234, 0.8),
0 0 0 0.5em rgba(167, 227, 234, 0.8);
top: 0%; left: 50%;
/* The "width" and "height" of the division must be smaller than the "box-shadow" total size. So we can control different variant sizes. */
width: 0.2em;
height: 0.2em;
animation: fall 3.5s cubic-bezier(0.5, 0, 1, 0.5) infinite;
}
/* Surface */
.drop:after {
background: rgb(52, 152, 219);
background: linear-gradient(rgba(52, 255, 255, 1) 0%, rgba(52, 152, 219, 1) 10%, rgba(152, 252, 219, 1) 100%);
border-radius: 100% 0 50% 0;
left: 0;
bottom: 0;
width: inherit;
height: 3em;
opacity: 0.7;
animation: surface 3s linear infinite;
}
/* Drop animation */
@keyframes fall {
/* Drop form */
5%, 15% {
box-shadow: 0 -1.4em 0 0.1em rgba(167, 217, 234, 1),
0 -0.8em 0 0.15em rgba(167, 217, 234, 1),
0 -0.3em 0 0.2em rgba(167, 217, 234, 1),
0 -0.1em 0 0.25em rgba(167, 217, 234, 1),
0 0 0 0.3em rgba(167, 217, 234, 1),
0 0.2em 0 0.35em rgba(167, 217, 234, 1),
0 0.4em 0 0.4em rgba(167, 217, 234, 1),
0 0.6em 0 0.45em rgba(167, 217, 234, 1),
0 0.8em 0 0.5em rgba(167, 217, 234, 1);
}
/* Drop fall */
16% {
top: 80%;
}
/* Contact surface */
18% {
top: 80%;
box-shadow: 1em -8em 0 0.2em rgba(177, 227, 234, 1),
-2.2em -3.8em 0 0.1em rgba(177, 227, 234, 1),
3em -2.85em 0 0.3em rgba(177, 227, 234, 1),
-3.5em -4em 0 0.2em rgba(177, 227, 234, 1),
0 0 0 0.3em rgba(177, 227, 234, 1),
2em -2em 0 0.2em rgba(177, 227, 234, 1),
-0.3em -3em 0 0.2em rgba(177, 227, 234, 1),
0.5em -5em 0 0.35em rgba(177, 227, 234, 1),
-3em -1em 0 0.3em rgba(177, 227, 234, 1);
}