JS+CSS仿魔兽游戏进入进度条特效

2 篇文章 0 订阅
<html>
 2 <head>
 3 <title>落日赌城</title>
 4 </head>
 5 <body>   
 6 </body>
 7 <script type="text/jscript">
 8 function DoubleAnimation(target,targetProperty,from,to,Duration)
 9 {
10     this.Begin=function anonymous()
11     {
12         target[targetProperty]=from;
13         var starttime=new Date();
14         setTimeout(StoryBoard(),1);
15         function StoryBoard()
16         {
17             return function()
18             {                 
19                 var now=new Date();
20                 var d=now.getTime()-starttime.getTime();
21                 target[targetProperty]=Math.round(from+(to-from)*d/Duration);
22                 if(d<Duration)setTimeout(StoryBoard(),10);
23             }
24         }
25     }
26     this.setTo=function(val){to=val;}
27     this.setFrom=function(val){from=val;}
28 } 
29 function ProgressBar(ID)
30 {
31     document.write( "<div id=\""+ID+"\" style=\"position:absolute;top:199;width:100; left: 108px;\"><image src=\"/images/20110805/pb_empty.jpg\" style=\"position: absolute;left: 84px; top: 137px;\" /><div id=\""+ID+"pb\" style=\"position: absolute; left: 106px; top: 143px;z-index:5;overflow:hidden;width:130;\" ><img src=\"/images/20110805/pb_full3.jpg\"/><div id=\""+ID+"highlight\" style=\"background:#ffffff;left: -500px; position: absolute; top: -1px;width:100;height:20;filter:Alpha(Opacity=75,FinishOpacity=0,Style=2)\"></div></div><div style=\"position:absolute;top:83px;width:180px; left: 148px;\">加载中请稍候……</div></div>");
32     document.write("<div id='light' style=\"position: absolute;height:10;width:20;left:1000;top:334;background:#aaccff;filter:progid:DXImageTransform.Microsoft.Blur(PixelRadius='10')progid:DXImageTransform.Microsoft.Alpha(opacity=50);\"></div>");
33     var story=new DoubleAnimation(document.getElementById(ID+"highlight").style,"left",-100,324,2000)
34     this.set=function(percentage)
35     {
36         document.getElementById(ID+"pb").style.width=Math.round(percentage*410/100);
37         document.getElementById("light").style.left=Math.round(percentage*410/100)+194;
38         document.getElementById("light").filters[1].opacity=percentage%100;
39     }
40 }
41 //演示
42 var pb1=new ProgressBar("ok");
43 var p=0;
44 function loading()
45 {
46 pb1.set(p+=0.1);
47 if(p<100)setTimeout(loading,10);
48 }
49  
50 loading()
51 </script>
52 <br />
54 </html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
HTML部分: ```html <div class="progress-ring"> <div class="progress-bar"></div> <div class="progress-value">0%</div> </div> ``` CSS部分: ```css .progress-ring { position: relative; width: 200px; height: 200px; } .progress-bar { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border-radius: 50%; box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1); } .progress-bar:before { position: absolute; content: ""; top: 0; left: 0; width: 100%; height: 100%; border-radius: 50%; background-color: #1abc9c; transform: rotate(-90deg); transform-origin: center; } .progress-value { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 30px; font-weight: bold; color: #1abc9c; } ``` JavaScript部分: ```javascript const progressBar = document.querySelector(".progress-bar"); const progressValue = document.querySelector(".progress-value"); let progress = 0; const interval = setInterval(() => { progress += 1; progressBar.style.backgroundImage = "linear-gradient(" + (90 + (progress / 100) * 360) + "deg, transparent 50%, #1abc9c 50%), linear-gradient(90deg, #1abc9c 50%, transparent 50%)"; progressValue.textContent = progress + "%"; if (progress >= 100) { clearInterval(interval); } }, 50); ``` 这段 JavaScript 代码会使进度条进度从 0% 逐渐增加到 100%。具体实现方式是通过设置 `progressBar` 元素的背景图片,利用 `linear-gradient` 渐变来实现环形进度条的效果。同时,也会动态更新进度值,将其显示在 `progressValue` 元素中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值