css+js实现静态和动态条形/环形进度条展示

css+js实现静态和动态进度条展示

css+js实现静态和动态进度条展示

css+js实现静态和动态进度条展示的思路见代码:
在这里插入图片描述

<html> 
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>进度条缓冲</title>
		<style type="text/css">
			*{margin:0;padding:0;}
		
			#wai{width:200px; height:20px; margin:10px 0px; border:1px solid #666;}
			#nei{width:0%; height:20px; background-color:#F00; float:left;}
			
			.wrap{width:110px;height:110px;position:relative;border-radius:50%;background:green;}
			.leftWrap{width:55px;height:110px;margin:0px;position:absolute;left:0;top:0;overflow:hidden;}
			.rightWrap{width:55px;height:110px;margin:0px;position:absolute;right:0;top:0;overflow:hidden;}
			.left{width:55px;height:110px;border-radius:55px 0 0 55px;background:#EBEEF5;transform-origin:right center;}
			.right{width:55px;height:110px;border-radius:0 55px 55px 0;background:#EBEEF5;transform-origin:left center;}
			.proportion{width:96px;height:96px;line-height:96px;position:absolute;top:7px;left:7px;background:#fff;border-radius:50%;text-align:center;font-size:20px;}
		</style>
	</head>
	<body>
		<!--环形进度条 -->
		<div class="wrap">
		  <div class="leftWrap">
				<div class="left"></div>
			</div>
			<div class="rightWrap">
				<div class="right"></div>
			</div>
			<div class="proportion">40%</div>
		</div>
		<!--条形进度条 -->
		<div id="wai">
			<div id="nei"></div>
		</div>
		<input type="button" value="开始缓冲" onclick="move()"/>
	</body>
	<script type="text/javascript">
	// 静态展示环形进度条
		var num = parseInt(document.getElementsByClassName("proportion")[0].innerText);
		var num_round = parseInt(document.getElementsByClassName("proportion")[0].innerText)*3.6;
		if(num_round<=180){
		  document.getElementsByClassName("left")[0].style.transform = "rotate(" + num_round + "deg)";
		}else{
		  document.getElementsByClassName("left")[0].style.transform = 'rotate(' + 180 + 'deg)';
		  document.getElementsByClassName("right")[0].style.transform = 'rotate(' + (num_round -180) + 'deg)';
		}
		// 静态展示条形进度条
		console.log(num,typeof(num))
		document.getElementById("nei").style.width = num + '%';
		
		//动态展示进度条
		var a=0;
		function move(){
			if(a<100){
				a++;
			}
			// 条形动态进度条
			document.getElementById("nei").style.width =a + "%";
			// 环形动态进度条
			let b = a*3.6;
			if(b <= 180){
			  document.getElementsByClassName("left")[0].style.transform = "rotate(" + b + "deg)";
			document.getElementsByClassName("right")[0].style.transform = 'rotate(' + 0 + 'deg)';
			}else{
			  document.getElementsByClassName("left")[0].style.transform = 'rotate(' + 180 + 'deg)';
			  document.getElementsByClassName("right")[0].style.transform = 'rotate(' + (b -180) + 'deg)';
			}
			window.setTimeout("move()",5);
		}
	</script>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值