html星空特效代码
来源:快懂网
2021-10-22 18:17
788 人看过
星空特效 *{ margin: 0; padding: 0;
品牌型号:联想 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;
-
推荐文章:
qq流星雨特效怎么弄(qq聊天流星雨特效怎么弄)
抖音面膜特效在哪里(抖音奶瓶面膜特效在哪里)
抖音运镜特效在哪里
- 延伸阅读:
- qq流星雨特效怎么弄(qq聊天流星雨特效怎么弄)
- 抖音面膜特效在哪里(抖音奶瓶面膜特效在哪里)
- 抖音运镜特效在哪里
免责声明:本站所提供的内容均来源于网友提供或网络搜集,由本站编辑整理,仅供个人研究、交流学习使用。如涉及版权问题,请联系本站管理员予以更改或删除。
给作者点赞,鼓励TA抓紧创作!
有用
788