运用CSS3实现钟摆效果
来源:互联网 发布:宏 知乎 编辑:程序博客网 时间:2024/04/28 12:37
目的:利用html5,css实现钟摆效果
知识点:
1) 利用position/left/top和calc()实现元素的水平和垂直居中;
2) 利用CSS3的animation/transform/transform-origin属性定义动画;
3) 利用transform-origin实现旋转原点的圆心调整
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <style> #box{ width:300px; height:300px; border: 6px solid red; //实现元素的水平垂直居中 position: absolute; top:calc(50% - 150px); left:calc(50% - 150px); } #innerCircle{ width:0; height:0; border: 10px solid cornflowerblue; border-radius: 10px; //实现元素的水平垂直居中 position: absolute; top:calc(50% - 10px); left:calc(50% - 10px); } #outerCircle{ width:6px; height:6px; background-color: yellow; border: 20px solid cornflowerblue; //实现元素位于父元素bottom center位置 position: absolute; top:calc(100% - 23px); left:calc(50% - 23px); animation: pendulum 4s infinite; //默认的origin为#outerCircle元素的左上角,即 0% 0% //本例中origin Y轴偏离量: // 300px/2 - 20px - 6px/2 transform-origin: 50% -127px; } #rope{ width:4px; height:150px; background-color: cornflowerblue; //布置#rope元素 position:absolute; top: 50%; left: calc(50% - 2px); animation: pendulum 4s infinite; //同#outerCircle,需要调整origin坐标 transform-origin: 50% 0; } @keyframes pendulum{ 0 {transform: rotate(0deg);} // 角度-负数为逆时针 // 摆动右侧最高点 25% {transform: rotate(-30deg);} 50% {transform: rotate(0deg);} // 摆动左侧最高点 75% {transform: rotate(30deg);} 100% {transform: rotate(0deg);} } </style> </head> <body> <div id = "box"> <div id = "innerCircle"></div> <div id = "outerCircle"></div> <div id = "rope"></div> </div> </body></html>
效果图
阅读全文
0 0
- 运用CSS3实现钟摆效果
- CSS3实现钟摆动态效果
- 仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
- cocos2d--仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
- 运用CSS3实现简单的时钟效果
- 自定义View实现钟摆效果进度条PendulumView
- 钟摆效果动画效果
- 运用css3 实现骰子3d旋转效果
- cocos2d-x学习笔记(五)仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
- (转)cocos2d-x学习笔记(五)仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
- cocos2d-x学习笔记(五)仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
- Cocos2d-x学习笔记(五)仿真树叶飘落效果的实现(精灵旋转、翻转、钟摆运动等综合运用)
- Android自定义View: 如何实现类钟摆的动画效果?
- 钟摆(圆锥摆)效果
- css3实现闪光效果
- css3实现按钮开关效果
- CSS3实现折纸效果
- css3实现手风琴效果
- 学习HTML第一周(二)
- 枚举
- sklearn中支持向量机的参数
- half-consecutive(未AC)
- Ubuntu16.04 上 Redis 4.0 及php-redis扩展的安装和使用
- 运用CSS3实现钟摆效果
- test
- Python ftplib
- hdu 2043 密码
- mysql
- ios 获取当前时间 以及前后一个月的时间
- 【LightOJ】1138---Trailing Zeros(二分)
- 中科爱讯WiFi探针在线下广告精准投放的解决方案
- cimiss获取数据