本文主要是介绍利用css3关键帧动画模仿摩天轮得旋转,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
思路:首先我们画一个大圆当作摩天轮得大轮子使他旋转 然后 画上几个小正方通过定位使他在边缘四周当作摩天轮得厢使他和大轮子反向旋转 保持一样得节奏
首先画一个大轮子使他顺时针旋转
.wheel{height: 750px;width: 750px;margin: auto;border-radius:50%;background-color: #2A71E2;/*背景图片顺时针旋转360*/animation:rotate 10s linear infinite;position: relative;top:50px;}/*使用关键帧动画*/@keyframes rotate{0%{ transform:rotate(0deg);}100%{transform:rotate(360deg);}}
<div class="wheel"> </div>
在画几个个小轮子
.box1{background-color: red;width: 100px;height: 100px;position: absolute;top: 0px;left: 196px}.box2{background-color: green;width: 100px;height: 100px;position: absolute;top: 182px;left: -38px;}
<div class="wheel"><div class="box1"> </div><div class="box2"></div></div>
这时小盒子市随着大轮子一起旋转的,这不是我我们需要的 我要小盒子 看上是没有方向的变化 所以我们需要给小盒子加上和大轮子相反的旋转方向
.rotate{/*设置图片得旋转中心*/transform-origin:50% 0;animation:boxrotate 10s linear infinite;}/*图片逆时针旋转360*/@keyframes boxrotate{0%{ transform:rotate(0deg);}100%{transform:rotate(-360deg);}}
<div class="wheel"><div class="box1 rotate"></div><div class="box2 rotate"> </div></div>
写的比较简单 也可以通过设计好的图片来进行美化
整体代码:
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title><style>.wheel{height: 500px;width: 500px;margin: auto;border-radius:50%;background-color: #2A71E2;/*背景图片顺时针旋转360*/animation:rotate 10s linear infinite;position: relative;top:50px;}/*使用关键帧动画*/@keyframes rotate{0%{ transform:rotate(0deg);}100%{transform:rotate(360deg);}}.box1{background-color: red;width: 100px;height: 100px;position: absolute;top: -41px;left: 196px;}.box2{background-color: green;width: 100px;height: 100px;position: absolute;top: 182px;left: -38px;}.rotate{/*设置图片得旋转中心*/transform-origin:50% 0;animation:boxrotate 10s linear infinite;}/*图片逆时针旋转360*/@keyframes boxrotate{0%{ transform:rotate(0deg);}100%{transform:rotate(-360deg);}}</style>
</head>
<body>
<div class="wheel"><div class="box1 rotate"></div><div class="box2 rotate"> </div></div>
</body>
</html>
这篇关于利用css3关键帧动画模仿摩天轮得旋转的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!