这是一款基于svg过滤器和css3制作的可爱小动物动画特效。该特效中使用html标签和svg结合制作动物的外形,并通过css3 animation动画来制作动物的各种动画特效。
使用方法
html结构
该特效在创建动物时使用了不同的技术,在创建哈士奇时使用的是css border-radius属性,而在创建狐狸时使用的是内联的svg背景图像。
2个例子都使用嵌套的div作为动物的身体,合理的组合这些元素有利于制作动物运动时各个部分的动画效果。
<!-- markup for the fox head --> <div class="fox-head"> <div class="fox-face"> <div class="fox-ears"> <div class="fox-ear"></div> <div class="fox-ear"></div> </div> <div class="fox-skull"></div> <div class="fox-front"></div> <div class="fox-eyes"></div> <div class="fox-nose"></div> </div> </div> <!-- markup for the husky head --> <div class="husky-head"> <div class="husky-ear"></div> <div class="husky-ear"></div> <div class="husky-face"> <div class="husky-eye"></div> <div class="husky-eye"></div> <div class="husky-nose"></div> <div class="husky-mouth"> <div class="husky-lips"></div> <div class="husky-tongue"></div> </div> </div> </div>
哈士奇的身体多数以圆形和椭圆形为主,所以需要使用大量的border-radius属性来制作。例如它的后腿的css代码为:
.husky-hind-leg { // ... border-top-left-radius: 35% 100%; border-top-right-radius: 40% 100%; }
另外一些部分不能单独使用border-radius属性来制作,必须和transform相结合,例如哈士奇的前腿。
.husky-front-legs > .husky-leg:before { transform: skewy(-30deg) skewx(10deg); transform-origin: top right; }
对于狐狸身体部分的创建,作者使用adobe illustrator来创建图形,然后将各个部分保存为svg图形。最后使用sass-svg将其转换为css样式:
.fox-nose:before { @include svg((viewbox: (0 0 168 168))) { // the nose @include svg('path', ( fill: $color-nose, d: 'm83.7,86.7c3.3,0,11.6-3.9,11.6-7.1c0-3.2-9.4-3.2-11.6-3.2c-2.2,0-11.6,0-11.6,3.2 c72.1,82.8,80.4,86.7,83.7,86.7z' )); // the line connecting the nose to the mouth @include svg('path', ( stroke: $color-nose, fill: none, d: 'm83.7,102.3v86.7' )); // the mouth @include svg('path', ( stroke: $color-nose, fill: none, d: 'm94.5,104.9c0,0-5.2-2.7-10.8-2.7c-5.6,0-10.8,2.7-10.8,2.7' )); } }
上面的代码会生成一个被编码后的内联的背景图像。
.fox-nose:before { background-image: url("data:image/svg+xml;charset=utf8,%3csvg..."); }
哈士奇:
狐狸:
以上就是基于svg和css3的可爱卡通小动物动画特效的内容。