Home  >  Article  >  Web Front-end  >  CSS3实现围绕任何点来旋转-续_html/css_WEB-ITnose

CSS3实现围绕任何点来旋转-续_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:30:401422browse

前天写过一篇文章 "CSS3实现围绕任何点来旋转",主要是实现围绕点来旋转.

今天我们继续用另外一种方式实现.

我们先来看代码

Html

 <div class="smile">☺</div>

Css

.smile{

margin:100px auto;

width: 80px;

height: 80px;

font-size: 80px;

animation: action 10s linear infinite;

}

@keyframes action {

from {

transform: rotate(0deg)  translate(100px) rotate(0deg);

}

to {

transform: rotate(360deg) translate(100px) rotate(-360deg);

}

}

其实从代码量来说,比之前的简化了不少. HTML使用的只有一个标签,也只使用了一个动画.

我们主要还是从动画入手, 在这里transform里面我们加入了三种动画,第一种和 第三保证的是笑脸能够旋转起来,保证笑脸是正脸.

如果不需要正脸,可以去掉一个.

中间那个动画是平移动画,也就是在选择的同时,笑脸做平移运动.这样就形成了围绕旋转运动.

要确定这个围绕点,得控制笑脸的位置,我这里的代码就直接是用margin来控制的.如果需要设置不同的点,可以使用定位来控制位置.这样灵活一点.(代码大家就可以自己敲一下,试一下效果)

本文属于吴统威的博客, 微信公众号:bianchengderen,QQ群:186659233 的原创文章,转载时请注明出处及相应链接:http://www.wutongwei.com/front/infor_showone.tweb?id=178 ,欢迎大家传播与分享.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn