html制作动态八卦图源码

动态八卦图

自动旋转的八卦图,一个html文件就行,如下动态图所示:

请添加图片描述
taijitu.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="taiji">
		</div>
	</body>
	<style>
		body{
			background:rgba(128,128,128,.2);
		}
		#taiji{
			margin: 50px auto;
			width: 600px;
			height: 600px;
			animation: rotate 3s linear infinite;
			animation-play-state: paused;
		}
		.taiji{
			width: 300px;
			height: 300px;
			border-radius: 50%;
			position: relative;
			margin: 200px auto;
			top:150px;
			background-image: linear-gradient(to right,black 50%, white 50%);
		}
		.taiji::before,.taiji::after{
			content: '';
			position: absolute;
			width: 30px;
			height: 30px;
			border-radius:50%;
			left:50%;
			transform: translateX(-50%);
		}
		.taiji::before{
			background-color: white;
			border: 60px solid black;
			top: 0;
		}
		.taiji::after{
			background-color: black;
			border: 60px solid white;
			bottom: 0;
		}
		.line{
			width: inherit;
			height: inherit;
			transform-origin:50% 50%;
			transition: all 0s;
			position: absolute;
		}
		.line1{
			height: 10px;
			width: 80px;
			background-color: #000000;
			margin: 10px auto;
		}
		.line2{
			display: flex;
			width: 80px;
			margin: 10px auto;
		}
		.line3,.line4{
			height: 10px;
			width: 35px;
			background-color: #000000;
		}
		.line4{
			margin-left: 10px;
		}
		@keyframes rotate{
			0%{
				transform: rotate(0deg);
			}
			100%{
				transform: rotate(360deg);
			}
		}
		#taiji:hover{
			animation-play-state: running;
		}
	</style>
	<script>
		var m = document.getElementById('taiji'),
			lineLists = ",2,02,12,012,01,1,0";
		lineLists = lineLists.split(',');
		//四周的黑线
		for(let i = 0; i < 8; i++){
			var	newNode = document.createElement("div");
			newNode.classList.add("line");
			for(let j = 0; j < 3; j++){
				let child = document.createElement("div");
				if(lineLists[i].indexOf(j) != -1){
					let c1 = document.createElement("div"),
						c2 = document.createElement("div");
					child.classList.add("line2");
					c1.classList.add("line3");
					c2.classList.add("line4");
					child.appendChild(c1);
					child.appendChild(c2);
				}else{
					child.classList.add("line1");
				}
				newNode.appendChild(child);
			}
			newNode.style.transform = `rotate(${i*45}deg)`;
			m.appendChild(newNode);
		}
		//太极图中间部分
		var	newNode = document.createElement("div");
		newNode.classList.add("taiji");
		m.appendChild(newNode);
		console.log(m);
	</script>
</html>

鼠标放在八卦图上面才会旋转哦!
请添加图片描述

  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

编程ID

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值