html星空特效代码

品牌型号:联想 YOGA 14c/系统版本:windows7<htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>星空特效</title><s...
品牌型号:联想 YOGA 14c/系统版本:windows7<htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>星空特效</title><style>*{margin:0;padding:0;}body{overflow:hidden;background-color:#000;}h1{position:absolute;line-height:50px;letter-spacing:5px;color:#fff;width:300px;top:40%;left:50%;margin-left:-200px;font-size:30px;}</style></head><body><h1></h1><canvas></canvas><script>varcanvas=document.querySelector("canvas");ctx=canvas.getContext("2d");w=canvas.width=window.innerWidth;h=canvas.height=window.innerHeight;varcanvas2=document.createElement("canvas");ctx2=canvas2.getContext("2d");canvas2.width=100;canvas2.height=100;vara=canvas2.width/2;vargrandient=ctx.createRadialGradient(a,a,0,a,a,a);grandient.addColorStop(0.025,'#fff');grandient.addColorStop(0.1,'hsl(220,59%,18%)');grandient.addColorStop(0.025,'hsl(220,60%,33%)');grandient.addColorStop(1,"transparent");ctx2.fillStyle=grandient;ctx2.beginPath();ctx2.arc(a,a,a,0,Math.PI*2);ctx2.fill();ctx2.closePath();varstars=[];varcount=0;functionStar(){this.pos=Math.floor(Math.random()*w/2-100);this.r=Math.floor(Math.random()*100);this.dx=w/2;this.dy=h/2;this.rand=Math.floor(Math.random()*360);this.speed=this.pos/100000;stars[count]=this;count++;}Star.prototype.draw=function(){varx=Math.sin(this.rand+1)*this.pos+this.dx;y=Math.cos(this.rand)*this.pos/2+this.dy;ctx.drawImage(canvas2,x-this.r/2,y-this.r/2,this.r,this.r);this.rand=this.rand+this.speed;}for(vari=0;i<1000;i++){newStar();}functionanmit(){ctx.clearRect(0,0,w,h);for(vari=0;i<stars.length;i++){stars[i].draw();}requestAnimationFrame(anmit);}anmit();varoH=document.getElementsByTagName("h1")[0];vararr=["浩瀚星辰"],index=0,arrLen=arr.length,strLen=arr[0].length;pos=0,row=0,str="",timer=null;functionprint(){while(row<index){str=str+arr[row]+"<br>";row++;}oH.innerHTML=str+arr[index].substring(0,pos);if(pos==strLen){index++;pos=0;if(index<arr.length){strLen=arr[index].length;timer=setTimeout(print,250);}}else{pos++;timer=setTimeout(print,250);}}setTimeout(print,250);</script></body></html>

品牌型号:联想 YOGA 14c/系统版本:windows7

核心答案要点:

星空特效 *{ margin: 0; padding: 0;

本文来自再可爱一点好了投稿,不代表舒华文档立场,如若转载,请注明出处:https://www.chinashuhua.cn/12/581075.html

打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
() 0
上一篇 06-07
下一篇 06-07

相关推荐

评论列表

联系我们

在线咨询: QQ交谈

邮件:admin@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信