Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use JavaScript to realize the countdown effect of Spring Festival

Shulou Source: shulou.com Published: 2022-06-02 02:33:30 11月13日 Update

< flakes; s++) { this.snowflakes.push(new Snowflake()); } } update() { this.ctx.clearRect(0, 0, this.width, this.height); for (let flake of this.snowflakes) { flake.update(); this.ctx.save(); this.ctx.fillStyle = '#FFF'; this.ctx.beginPath(); this.ctx.arc(flake.x, flake.y, flake.radius, 0, Math.PI * 2); this.ctx.closePath(); this.ctx.globalAlpha = flake.alpha; this.ctx.fill(); this.ctx.restore(); } requestAnimationFrame(this.updateBound); }}new Snow();var stop = false;function show_runtime() { var newDay = '2022/2/1 00:00:00'; var countDate = new Date(newDay); var now = new Date().getTime(); gap = countDate - now; var second = 1000; var minute = second * 60; var hour = minute * 60; var day = hour * 24; var d = Math.floor(gap / day); var h = Math.floor((gap % day) / hour); var m = Math.floor((gap % hour) / minute); var s = Math.floor((gap % minute) / second); if ((d, h, m, s < 0)) { stop = true; } else { document.getElementById('day').innerText = d; document.getElementById('hour').innerText = h; document.getElementById('minute').innerText = m; document.getElementById('second').innerText = s; }}function newyear() { document.getElementById('title').innerText = 'Happy Spring Festival'; document.getElementById('day').innerText = '春'; document.getElementById('hour').innerText = '节'; document.getElementById('minute').innerText = '快'; document.getElementById('second').innerText = '乐';}var time = setInterval(() =>

{show_runtime (); if (stop = true) {newyear (); clearInterval (time);}}, 1000); / / timer controls the automatic switching of pictures function downTime () {let item = 1; setInterval () = > {item++; if (item = 4) {item = 1;} console.log (item, 'item') Document.body.style.backgroundImage = `url (. / image/geyao$ {item} .jpg) `; return item; e.stopPropagation (); / / cancel event bubbling}, 2000);} _ window.onload = downTime; effect demonstration mobile terminal

Pc end

Thank you for reading! This is the end of the article on "how to use JavaScript to achieve the countdown effect of the Spring Festival". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Countdown effects content more style article part switch move good practical event picture timer article look knowledge background reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB vpn Microsoft macOS Apple