css3实现围绕圆心公转的方法:1、创建一个HTML示例文件;2、定义一个div;3、通过“.out {border-radius: 150px;background-color: sandybrown;...”属性设置外层圆;4、使用animation和transform等属性定义基点并实现围绕圆心公转即可。

本教程操作环境:Windows10系统、CSS3版、DELL G3电脑
css3怎么实现围绕圆心公转?
CSS3动画 表情包围绕圆公转而不自转
效果如图
立即学习“前端免费学习笔记(深入)”;

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>公转不自转</title>
<style>
/* 外层圆 */
.out {
margin-top: 200px;
margin-left: 200px;
position: relative;
height: 300px;
width: 300px;
border-radius: 150px;
background-color: sandybrown;
box-shadow: 0 0 23px;
}
/* 笑脸的容纳框 */
.cover {
display: inline-block;
width: 50px;
height: 50px;
position: absolute;
/* 定义基点 */
transform-origin: 150px 150px;
animation: smile linear 5s infinite;
background-color: springgreen;
}
/* 笑脸表情包*/
img {
width: 50px;
height: 50px;
/*方法1 不自转只需要reverse反向线性就可以了*/
animation: smile reverse linear 5s infinite;
}
@keyframes smile {
to {
transform: rotateZ(360deg);
}
}
/* 方法2 */
/* 默认情况下笑脸会跟随容纳框再5s内旋转360deg,所以只要再变换曲线相同的情况下再让它倒着转360deg就好啦 */
/* @keyframes no-rotate {
to {
transform: rotateZ(-360deg);
}
} */
/* 文本的绝对居中 */
.out span {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 20px;
}
</style>
</head>
<body>
<div>
<div>
<img
src="https://ss0.bdstatic.com/94oJfD_bAAcT8t7mm9GUKT-xh_/timg?image&quality=100&size=b4000_4000&sec=1577100031&di=7445f215ef1f860d45fd93be22b52f57&src=http://git.oschina.net/uploads/group/110103951448978.jpg"
alt="">
</div>
<span>和蔼的笑脸</span>
</div>
</body>
</html>推荐学习:《css视频教程》
以上就是css3怎么实现围绕圆心公转的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号