动画实现始终效果案例(动画的使用,居中的使用)

27 篇文章 0 订阅

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>时钟案例</title>
		<style type="text/css">
			* {
				padding: 0;
				margin: 0;
			}
			.clock {
				width: 300px;
				height: 300px;
				border: 10px solid #CCCCCC;
				/* border-radius: 160px; */
				/* 百分比参照元素的实际宽高 */
				border-radius: 50%;
				margin: 100px auto;
				position: relative;
			}

			/* 先设置共同的样式 */
			.line {
				width: 8px;
				height: 300px;
				background-color: #CCCCCC;
				position: absolute;
				left: 50%;
				/* 参照父元素 */
				top: 0;
				/* 参照元素本身 */
				transform: translate(-50%, 0);
			}
			.line1, .line4 {
				/* 统一针对线条1,4设置宽一些 */
				width: 10px;
			}
			.line2 {
				/* 要把之前的transform值也写一份,不然会有UI异常。 */
				transform: translate(-50%, 0) rotate(30deg);
			}
			.line3 {
				transform: translate(-50%, 0) rotate(60deg);
			}
			.line4 {
				transform: translate(-50%, 0) rotate(90deg);
			}
			.line5 {
				transform: translate(-50%, 0) rotate(120deg);
			}
			.line6 {
				transform: translate(-50%, 0) rotate(150deg);
			}

			.cover {
				width: 250px;
				height: 250px;
				border-radius: 50%;
				background-color: #fff;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
			}
			.hour {
				width: 6px;
				height: 80px;
				background-color: red;
				position: absolute;
				/* 定位 */
				left: 50%;
				/* 水平居中 */
				top: 50%;
				transform: translate(-50%, -100%);
				transform-origin: center bottom;
				/* 添加动画 */
				animation: clockAnimation 43200s linear infinite ;
			}
			.minute {
				width: 4px;
				height: 100px;
				background-color: green;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -100%);
				transform-origin: center bottom;
				/* 添加动画 */
				animation: clockAnimation 3600s linear infinite ;
			}
			.second {
				width: 2px;
				height: 120px;
				background-color: gray;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -100%);
				/* 设置旋转轴心 */
				transform-origin: center bottom;
				/* 添加动画 */
				animation: clockAnimation 60s linear infinite ;
				/* steps与animation-timing-function的其他属性冲突 */
				animation-timing-function: steps(60);
			}
			.center {
				width: 20px;
				height: 20px;
				background-color: #CCCCCC;
				position: absolute;
				left: 50%;
				top: 50%;
				border-radius: 10px;
				transform: translate(-50%, -50%);
			}
			/* 创建动画 */
			@keyframes clockAnimation {
				from {
					transform: translate(-50%, -100%) rotate(0deg);
				}
				to {
					transform: translate(-50%, -100%) rotate(360deg);
				}
			}
		</style>
	</head>
	<body>
		<div class="clock">
			<div class="line line1"></div>
			<div class="line line2"></div>
			<div class="line line3"></div>
			<div class="line line4"></div>
			<div class="line line5"></div>
			<div class="line line6"></div>
			<!-- 覆盖物 -->
			<div class="cover"></div>
			<div class="hour"></div>
			<div class="minute"></div>
			<div class="second"></div>
			<div class="center"></div>
		</div>
		</div>
	</body>
</html>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值