如何使用JS實作520程式碼
這次帶給大家如何使用JS實作520程式碼,使用JS實作520程式碼的注意事項有哪些,以下就是實戰案例,一起來看一下。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>520</title> <style> html, body{padding:0px; margin:0px; background:#222; font-family: 'Karla', sans-serif; color:#FFF; height:100%; overflow:hidden;} canvas {width:100%; height:100%;} #text,#text_520{font-family:'楷体'; color:rgb(255,255,3); font-size:20px; position:fixed; left:10%; top:10%;} #text_520{font-size:100px; top:50%; left:50%;} img{position:fixed; top:0; left:0; width:100%;} #last{font-size:12px; bottom:10px; left:50%; position:fixed;} /* @keyframes drop { 0% { transform: translateY(-100px); opacity: 0; } 90% { opacity: 1; transform:translateY(10px); } 100% { transform:translateY(0px;) } } */ </style> </head> <body> <canvas id="c"></canvas> <p id="text"></p> <p id="text_520">5 2 0</p> <img src="./timg.jpg" class="img" /> <p id="last">版权所有:李晓珂</p> <script type="text/javascript" src="./jquery-1.11.0.min.js"></script> <script type="text/javascript"> function isIE(){ var u = navigator.userAgent; if((u.indexOf("compatible") > -1 && u.indexOf("MSIE") > -1) || (u.indexOf("Trident") > -1 && u.indexOf("rv:11.0") > -1)){ alert("该浏览器暂不支持,请更换浏览器"); window.open('','_self'); window.close(); } var audio = document.createElement("audio"); audio.setAttribute("src","./520-love.mp3"); audio.setAttribute("autoplay","autoplay"); } isIE(); </script> <script type="text/javascript"> var textArr = [ 'I love three things in this world,', 'the sun ,the moon and you.', 'The sun for the day,', 'the moon for the night,', 'and you forever!', '', 'If you were a teardrop,', 'in my eye,', 'for fear of losing you,', 'I would never cry.', 'And if the golden sun,', 'should cease to shine its light,', 'just one smile from you,', 'would make my whole world bright.' ]; var text_520 = document.getElementById('text_520'); var height = (window.innerHeight - text_520.offsetHeight) / 2; var width = (window.innerWidth - text_520.offsetWidth) / 2; text_520.style.top = height + 'px'; text_520.style.left = width + 'px'; $('#text_520').hide(); $('.img').hide(); var m = 0; var n = 0; var text = document.getElementById('text'); function typing(){ if(m <= textArr[n].length) { text.innerHTML = text.innerHTML.substring(0,text.innerHTML.length-1) + textArr[n].substr(m++,1) + '_'; setTimeout(typing,250); }else { if(n < textArr.length-1){ text.innerHTML = text.innerHTML.substring(0,text.innerHTML.length-1) + "<br />_"; n++; m = 0; typing(); }else { text.innerHTML = text.innerHTML.substring(0,text.innerHTML.length-1); $('#text').fadeOut(5000); setTimeout(function(){$('#text_520').fadeIn(5000);},7000); setTimeout(function(){$('#text_520').fadeOut(5000); },7000); setTimeout(function(){$('.img').fadeIn(50000);},15000) } } } setTimeout(typing,5000); var ctx = document.querySelector('canvas').getContext('2d'); ctx.canvas.width = window.innerWidth; ctx.canvas.height = window.innerHeight; var sparks = []; var fireworks = []; var walker; fireworks.pop(); var i = 10; while(i--) fireworks.push(new Firework(Math.random()*window.innerWidth, window.innerHeight*Math.random())); // setInterval(render, 1000/50); render(); function render() { setTimeout(render, 1000/50); ctx.fillStyle = 'rgba(0, 0, 0, 0.2)'; ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); // 上升效果 for(var firework of fireworks) { if(firework.dead) continue; firework.move(); firework.draw(); } // 绽放效果 for(var spark of sparks) { if(spark.dead) continue; spark.move(); spark.draw(); } if(Math.random() < 0.1) fireworks.push(new Firework()); //ctx.height = ctx.height; } function Spark(x, y, color) { this.x = x; this.y = y; this.dir = Math.random() * (Math.PI*2); this.dead = false; this.color = color; this.speed = Math.random() * 3 + 3; walker = new Walker({ radius: 20, speed: 0.25 }); this.gravity = 0.25; this.dur = this.speed / 0.15; this.move = function() { this.dur--; if(this.dur < 0) this.dead = true; if(this.speed < 0) return; if(this.speed > 0) this.speed -= 0.15; walk = walker.step(); this.x += Math.cos(this.dir + walk) * this.speed; this.y += Math.sin(this.dir + walk) * this.speed; this.y += this.gravity; this.gravity += 0.05; } this.draw = function() { drawCircle(this.x, this.y, 2, this.color); } } function Firework(x, y) { this.xmove = Math.random()*2 - 1; this.x = x || Math.random() * ctx.canvas.width; this.y = y || ctx.canvas.height; this.height = Math.random()*ctx.canvas.height/2; this.dead = false; this.color = randomColor(); this.move = function() { this.x += this.xmove; if(this.y > this.height) this.y -= 4; else this.burst(); } this.draw = function() { drawCircle(this.x, this.y, 3, this.color) } this.burst = function() { this.dead = true i = 100; while(i--) sparks.push(new Spark(this.x, this.y, this.color)); sparks.pop(); } } setTimeout(function (){window.open('','_self').close();},175000); /* // 清除两个数组 function clear(){ if(sparks!=null || fireworks!=null){ sparks.pop(); fireworks.pop(); } var sparks = []; var fireworks = []; } setInterval(clear,100); */ function drawCircle(x, y, radius, color) { color = color || '#FFF'; ctx.fillStyle = color; ctx.fillRect(x-radius/2, y-radius/2, radius, radius); } function randomColor(){ return ['#6ae5ab','#88e3b2','#36b89b','#7bd7ec','#66cbe1'][Math.floor(Math.random() * 5)]; } function Walker(options){ this.step = function(){ this.direction = Math.sign(this.target) * this.speed this.value += this.direction this.target ? this.target -= this.direction : (this.value) ? (this.wander) ? this.target = this.newTarget() : this.target = -this.value : this.target = this.newTarget() return this.direction } this.newTarget = function() { return Math.round(Math.random()*(this.radius*2)-this.radius) } this.start = 0 this.value = 0 this.radius = options.radius this.target = this.newTarget() this.direction = Math.sign(this.target) this.wander = options.wander this.speed = options.speed || 1 } </script> </body> </html>
我相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
怎麼使用基於Vue的延遲載入外掛程式vue-view-lazy
以上是如何使用JS實作520程式碼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

華為手機如何實現雙微信登入?隨著社群媒體的興起,微信已成為人們日常生活中不可或缺的溝通工具之一。然而,許多人可能會遇到一個問題:在同一部手機上同時登入多個微信帳號。對於華為手機用戶來說,實現雙微信登入並不困難,本文將介紹華為手機如何實現雙微信登入的方法。首先,華為手機自帶的EMUI系統提供了一個很方便的功能-應用程式雙開。透過應用程式雙開功能,用戶可以在手機上同

程式語言PHP是一種用於Web開發的強大工具,能夠支援多種不同的程式設計邏輯和演算法。其中,實作斐波那契數列是一個常見且經典的程式設計問題。在這篇文章中,將介紹如何使用PHP程式語言來實作斐波那契數列的方法,並附上具體的程式碼範例。斐波那契數列是一個數學上的序列,其定義如下:數列的第一個和第二個元素為1,從第三個元素開始,每個元素的值等於前兩個元素的和。數列的前幾元

如何在華為手機上實現微信分身功能隨著社群軟體的普及和人們對隱私安全的日益重視,微信分身功能逐漸成為人們關注的焦點。微信分身功能可以幫助使用者在同一台手機上同時登入多個微信帳號,方便管理和使用。在華為手機上實現微信分身功能並不困難,只需要按照以下步驟操作即可。第一步:確保手機系統版本和微信版本符合要求首先,確保你的華為手機系統版本已更新至最新版本,以及微信App

在現今的軟體開發領域中,Golang(Go語言)作為一種高效、簡潔、並發性強的程式語言,越來越受到開發者的青睞。其豐富的標準庫和高效的並發特性使它成為遊戲開發領域的一個備受關注的選擇。本文將探討如何利用Golang來實現遊戲開發,並透過具體的程式碼範例來展示其強大的可能性。 1.Golang在遊戲開發中的優勢作為靜態類型語言,Golang正在建構大型遊戲系統

在Golang中實現精確除法運算是一個常見的需求,特別是在涉及金融計算或其它需要高精度計算的場景中。 Golang的內建的除法運算子「/」是針對浮點數計算的,並且有時會出現精度遺失的問題。為了解決這個問題,我們可以藉助第三方函式庫或自訂函數來實現精確除法運算。一種常見的方法是使用math/big套件中的Rat類型,它提供了分數的表示形式,可以用來實現精確的除法運算

PHP遊戲需求實現指南隨著網路的普及和發展,網頁遊戲的市場也越來越火爆。許多開發者希望利用PHP語言來開發自己的網頁遊戲,而實現遊戲需求是其中一個關鍵步驟。本文將介紹如何利用PHP語言來實現常見的遊戲需求,並提供具體的程式碼範例。 1.創造遊戲角色在網頁遊戲中,遊戲角色是非常重要的元素。我們需要定義遊戲角色的屬性,例如姓名、等級、經驗值等,並提供方法來操作這些

實在抱歉,我無法提供即時的程式設計指導,但我可以為你提供一篇程式碼範例,讓你更能理解如何使用PHP實作SaaS。以下是一篇1500字以內的文章,標題為《使用PHP實作SaaS:全面解析》。在當今資訊時代,SaaS(SoftwareasaService)已經成為了企業和個人使用軟體的主流方式,它提供了更靈活、更便利的軟體存取方式。透過SaaS,用戶無需在本地

標題:利用Golang實現資料匯出功能詳解隨著資訊化程度的提升,許多企業和組織需要將儲存在資料庫中的資料匯出到不同的格式中,以便進行資料分析、報表產生等用途。本文將介紹如何利用Golang程式語言實作資料匯出功能,包括連接資料庫、查詢資料和匯出資料到檔案的詳細步驟,並提供具體的程式碼範例。連接資料庫首先,我們需要使用Golang中提供的資料庫驅動程序,例如da
