H5 移动端进度条加载

该博客展示了如何在H5移动端实现一个进度条加载效果。通过CSS样式定义了加载条的外观,并使用JavaScript模拟了资源加载的进度更新,通过调整加载条宽度和数字显示来动态展示加载状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>移动端进度条</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<style>
			html {
			  font-size: 20px;
			}
			body {
			  font-size: 16px;
			  font-family: "微软雅黑";
			}
			@media only screen and (max-width: 320px) {    html { 
			        font-size: 42.7px !important; 
			    }} 
			@media only screen and (min-width: 321px) and (max-width: 360px) {    html { 
			        font-size: 48px !important; 
			    }} 
			@media only screen and (min-width: 361px) and (max-width: 375px) {    html { 
			        font-size: 50px !important; 
			    }} 
			@media only screen and (min-width: 376px) and (max-width: 384px) {    html { 
			        font-size: 52.1px !important; 
			    }} 
			@media only screen and (min-width: 385px) and (max-width: 414px) {    html { 
			        font-size: 55.2px !important; 
			    }} 
			@media only screen and (min-width: 415px) and (max-width: 480px) {    html { 
			        font-size: 64px !important; 
			    }} 
			@media only screen and (min-width: 481px) and (max-width: 540px) {    html { 
			        font-size: 72px !important; 
			    }}
			@media only screen and (min-width: 750px) {    html { 
			        font-size: 100px !important; 
			    }}
    
			.loading_fater{
				width: 4.14rem;
				height: 0.44rem;
				background: #391956;
				border: 3px solid #FFFFFF;
				box-shadow: 0 3px 7px 0 rgba(189,16,224,0.50);
				border-radius: 100px;
				text-align: center;
			}
			.loading{ 
				width: 0.14rem;
				height: 0.44rem;
				background: #FE6365;
				box-shadow: inset 0 0 4px 0 #470707;
				border-radius: 100px;
			}
			.loading_fater> span{
				color: white;
				text-align: center;
				position: absolute;
				top: 0.1rem;
				left: 2rem;
			}
			
		</style>
	</head>
	<body>
		
		<div class="loading_fater">
			<div class="loading"></div>
			<span><label class="bfb">0</label>%</span>
		</div>
		
		<script type="text/javascript"> 
			
			/**
			 * 由于js并不能获取下载所需资源包文件大小 
			 * 所以只能在页面个部位插入代码片段 更新进度条 以模拟资源下载(读取)进度
			 */
			
			
			updateLoading(20,500);
			
			//用延迟  模拟加载文件需要的时间
			setTimeout(function(){
				updateLoading(30,500);
			},1000)
			
			
			setTimeout(function(){
				updateLoading(60,500);
			},2000)
			
			
			setTimeout(function(){
				updateLoading(100,1000);
			},3000)
			
			var bfb = document.getElementsByClassName('bfb')[0];
			/**
			 * 更新进度条
			 * @param {Object} bfb_num :更新进度条数字baifenbi (10)
			 * @param {Object} millisecond :动画执行毫秒数
			 */
			function updateLoading(bfb_num,millisecond){
				
				//$('.loading').animate({'width':bfb_num+"%"},millisecond); 
				document.getElementsByClassName('loading')[0].style.cssText = 'width: '+bfb_num+'%;transition-duration:'+millisecond+'s;'
				
				var load_Interval = setInterval(function(){
					if(bfb.innerHTML < bfb_num){
						bfb.innerHTML = parseInt(bfb.innerHTML)+1;
					}else{
						clearInterval(load_Interval);
					}
				},millisecond/bfb_num)
			}
			
		</script> 
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值