In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
The knowledge of this article "how to use JS to achieve code rain special effects" is not understood by most people, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use JS to achieve code rain special effects" article.
Html code
Js code
_ window.onload = function () {/ / get canvas object var canvas = document.getElementById ("code_rain_canvas"); / / get canvas context var context = canvas.getContext ("2d"); var s = window.screen; var W = canvas.width = s.width; var H = canvas.height / / get the width and height of the browser screen / / var W = window.innerWidth; / / var H = window.innerHeight; / / set the width and height of canvas canvas.width = W; canvas.height = H; / / the font size of each text var fontSize = 12 / / calculate the column var colunms = Math.floor (W / fontSize); / / record the y-axis coordinates of each column of text var drops = []; / / initialize the position of a starting point for each text for (var I = 0; I)
< colunms; i++) { drops.push(0); } //运动的文字 var str = "WELCOME TO WWW.ITRHX.COM"; //4:fillText(str,x,y);原理就是去更改y的坐标位置 //绘画的函数 function draw() { context.fillStyle = "rgba(238,238,238,.08)"; //遮盖层 context.fillRect(0, 0, W, H); //给字体设置样式 context.font = "600 " + fontSize + "px Georgia"; //给字体添加颜色 context.fillStyle = ["#33B5E5", "#0099CC", "#AA66CC", "#9933CC", "#99CC00", "#669900", "#FFBB33", "#FF8800", "#FF4444", "#CC0000"][parseInt(Math.random() * 10)]; //randColor();可以rgb,hsl, 标准色,十六进制颜色 //写入画布中 for (var i = 0; i < colunms; i++) { var index = Math.floor(Math.random() * str.length); var x = i * fontSize; var y = drops[i] * fontSize; context.fillText(str[index], x, y); //如果要改变时间,肯定就是改变每次他的起点 if (y >= canvas.height & & Math.random () > 0.99) {drops [I] = 0;} drops [I] +;}}; function randColor () {/ / Random color var r = Math.floor (Math.random () * 256) Var g = Math.floor (Math.random () * 256); var b = Math.floor (Math.random () * 256); return "rgb (" + r + "," + g + "," + b + ")";} draw (); setInterval (draw, 35);}
Display effect:
The above is about "how to use JS to achieve code rain special effects" of this article, I believe we all have a certain understanding, I hope the editor to share the content to help you, if you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.