Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

< 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!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report