1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > html+css+js实现星空旋转和文字淡入效果(code)

html+css+js实现星空旋转和文字淡入效果(code)

时间:2024-03-13 17:30:13

相关推荐

html+css+js实现星空旋转和文字淡入效果(code)

web前端|html教程

html,css

web前端-html教程

本篇文章给大家通过代码示例介绍一下使用html+css+js如何实现一个星空旋转和文字逐渐出现的效果。有一定的参考价值,有需要的朋友可以参考一下,希望对你们有所助。

影视网站源码.zip,ubuntu连接腾讯云,tomcat8是否支持ejb,爬虫 主机拒绝,php招聘的多吗,蚁群seolzw

web软件源码下载,vscode代码不跳转,ubuntu 网络 不见,tomcat样板页,如何编写sqlite数据库,爬虫爬取各大新闻网站,php家教网源码,外包服务郑州seo优化,网站手机版绑定域名,手机图文列表html模板lzw

废话不多说直接上代码,效果是一个星空旋转和文字逐渐出现的效果,文字是逐渐出现的,星空中的小球是旋转的

八卦新闻源码,vscode打不开chrome,dev格式 ubuntu,tomcat注入源码,php留言板sqlite,前端微信小程序 用什么框架,手机app爬虫抓包工具,php乐观锁,seo客服没经验,卖asp网站代码的,更改了网页源代码后怎么再生成新的网页,html5登录模板lzw

星空特效*{ 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; } var canvas=document.querySelector("canvas"); ctx=canvas.getContext("2d"); w=canvas.width=window.innerWidth; h=canvas.height=window.innerHeight; var canvas2=document.createElement("canvas");ctx2=canvas2.getContext("2d");canvas2.width=100;canvas2.height=100; var a=canvas2.width/2; var grandient=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(); var stars=[]; var count=0; function Star(){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(){var x=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(var i=0;i<1000;i++){new Star(); } function anmit(){ctx.clearRect(0,0,w,h);for(var i=0;i<stars.length;i++){ stars[i].draw();}requestAnimationFrame(anmit); } anmit(); var oH=document.getElementsByTagName("h1")[0]; var arr=["这世间过于俗气","不像你一般","浩瀚星辰,温柔婉转"],index=0,arrLen=arr.length,strLen=arr[0].length;pos=0,row=0,str="",timer=null; function print() {while(row<index){ str=str+arr[row]+"

"; 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);

效果图:

Html视频教学

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。