雪花特效 烟花特效 以及 图片居中
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>每日风吟</title> <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script> <style> ul, li { text-indent: 0; text-decoration: none; margin: 0; padding: 0 } img { border: 0 } canvas { display: block; left: 0; position: absolute; top: 0; z-index: 1 } *{ margin: 0px; padding: 0px; } .time_xx{ font-weight: 900; word-spacing:3px; font-size:25px; position:absolute; height:40px; bottom:0; top:70%; left:0; right:0; margin:auto; text-align: center; font-family:"YouYuan"; text-shadow: 0 1px black, 1px 0 black, -1px 0 black, 0 -1px black; } #xh{ position: relative; } .xue { position: absolute; display: inline-block; /* opacity: .7; */ outline: none; border: none; animation: xuehua 5s infinite linear; } .xue:hover { cursor: pointer; animation-play-state: paused; opacity: 1; } @keyframes xuehua{ from{ opacity: 1; transform: translate(0, 0) rotate(0deg); } to{ opacity: 0; transform: translate(0, 700px) rotateZ(720deg) rotateY(720deg) scale(1.5); } } #back_body{ width: 100%; height: calc(100vh); z-index:-1; text-align: center; display: flex; align-items: center; justify-content: center; } </style> </head> <body style="background-color:black; color: white;"> <div id="xh"></div> <div class="time_xx"></div> <div id="back_body"> <!-- <img src="123.jpg" style="vertical-align: middle;" /> --> </div> <script type="text/javascript"> var xh = document.getElementById("xh"); /// 屏幕宽度 var dWidth = document.body.scrollWidth; var dHeight = window.innerHeight; var setXH = setInterval(function(){production();}, 100); xh.style.height = dHeight; function production() { var t1 = document.createElement("div"); /// left 和 top 最大值 /// left 减掉 100 是为了不产生横行的滑动条 var t1Left = Math.floor(Math.random() * dWidth) - 100; var t1Top = Math.floor(Math.random() * 10); t1.style.left = t1Left + "px"; t1.style.top = t1Top + "px"; t1.style.display = "inline-block"; t1.innerText = "❉";//❉ t1.style.color = "white"; t1.classList.add("xue"); /// 将生成的雪花加入到 div 下面去 xh.appendChild(t1); setInterval(function(){ t1.remove(); }, 5000); } </script> <script type="text/javascript"> // document.getElementById('back_body').style.color = "white"; // document.getElementById('back_body').style.backgroundColor = "#039BE5"; // document.getElementById('back_body').style.backgroundImage = "url('https://api.ixiaowai.cn/api/api.php')"; // setInterval(() => { // Draw(); // }, 500); window.onload = function () { Draw(); } var nyear; var nmonth; var nday = -1; var nwday; var nhrs; var nmin; var nsec; var lmonth, lday, lleap; //农历参数 function Draw() { NewTick(); //显示时间 var s = nyear + '年' + nmonth + '月' + nday + '日 ' + '星期' + cweekday(nwday) + ' ' + shapetime(nhrs, nmin, nsec); s += " 农历" + lmonth + "月" + lday; //农历 var lunar_month_day = lmonth + "月 "+ "⭐ " + lday; var my = lunar_month_day; //需要展示在页面地方 //console.log(lunar_month_day); $(".time_xx").text(my); } function NewTick() { noww = new Date(); if (noww.getDate() != nday) { nyear = noww.getFullYear(); nmonth = noww.getMonth() + 1; nwday = noww.getDay(); nday = noww.getDate(); getlunar(); //获取农历 } nhrs = noww.getHours(); nmin = noww.getMinutes(); nsec = noww.getSeconds(); } //辅助函数 var hzWeek = new Array("日", "一", "二", "三", "四", "五", "六", "日"); function cweekday(wday) { return hzWeek[wday]; } function shapetime(vhrs, vmin, vsec) { if (vsec <= 9) vsec = "0" + vsec; if (vmin <= 9) vmin = "0" + vmin; if (vhrs <= 9) vhrs = "0" + vhrs; return vhrs + ":" + vmin + ":" + vsec } //农历函数开始 var lunarInfo = new Array(0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5b0, 0x14573, 0x052b0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b6a0, 0x195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x05ac0, 0x0ab60, 0x096d5, 0x092e0, //1990 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0x0dd45, 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0, 0x14b63); function lYearDays(y) { var i, sum = 348; for (i = 0x8000; i > 0x8; i >>= 1) sum += (lunarInfo[y - 1900] & i) ? 1 : 0; return (sum + leapDays(y)); } function leapDays(y) { if (leapMonth(y)) return ((lunarInfo[y - 1900] & 0x10000) ? 30 : 29); else return (0); } function leapMonth(y) { return (lunarInfo[y - 1900] & 0xf); } function monthDays(y, m) { return ((lunarInfo[y - 1900] & (0x10000 >> m)) ? 30 : 29); } function Lunar(y, m, d) { var i, leap = 0, temp = 0; var offset = (Date.UTC(y, m, d) - Date.UTC(1900, 0, 31)) / 86400000; for (i = 1900; i < 2050 && offset > 0; i++) { temp = lYearDays(i); offset -= temp; } if (offset < 0) { offset += temp; i--; } this.year = i; leap = leapMonth(i); this.isLeap = false; for (i = 1; i < 13 && offset > 0; i++) { if (leap > 0 && i == (leap + 1) && this.isLeap == false) { --i; this.isLeap = true; temp = leapDays(this.year); } else { temp = monthDays(this.year, i); } if (this.isLeap == true && i == (leap + 1)) this.isLeap = false; offset -= temp; } if (offset == 0 && leap > 0 && i == leap + 1) if (this.isLeap) { this.isLeap = false; } else { this.isLeap = true; --i; } if (offset < 0) { offset += temp; --i; } this.month = i; this.day = offset + 1; } var nStr1 = new Array('', '一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'); var nStr2 = new Array('初', '十', '廿', '卅', '□'); function GetcDay(d) { var s; switch (d) { case 10: s = '初十'; break; case 20: s = '二十'; break; case 30: s = '三十'; break; default: s = nStr2[Math.floor(d / 10)]; s += nStr1[d % 10]; break; } return (s); } function GetcMon(m) { if (m == 1) return '正'; else return nStr1[m]; } function getlunar() { var lObj = new Lunar(nyear, nmonth - 1, nday); lmonth = GetcMon(lObj.month); lday = GetcDay(lObj.day); lleap = lObj.isLeap; if (lleap == 1) { lmonth = "闰" + lmonth; } } //农历函数结束 </script> <script type="text/javascript"> $(function () { var Fireworks = function () { var self = this; var rand = function (rMi, rMa) { return ~~((Math.random() * (rMa - rMi + 1)) + rMi); } var hitTest = function (x1, y1, w1, h1, x2, y2, w2, h2) { return !(x1 + w1 < x2 || x2 + w2 < x1 || y1 + h1 < y2 || y2 + h2 < y1); }; window.requestAnimFrame = function () { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window .mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (a) { window.setTimeout(a, 1E3 / 60) } }(); setInterval(function(){ if(self.fireworks.length>5){ self.fireworks.clear(); } var number = rand(1, 3); for(var i=0;i<number;i++){ self.partSpeedVariance = rand(1, 7); var dWidth = document.body.scrollWidth; var dHeight = window.innerHeight; var t1Left = Math.floor(Math.random() * dWidth/2 + dWidth/4); var t1Top = Math.floor(Math.random() * dHeight/2 + 100); self.mx = t1Left - self.canvas.offsetLeft; self.my = t1Top - self.canvas.offsetTop; self.currentHue = rand(self.hueMin, self.hueMax); self.createFireworks(self.cw / 2, self.ch, self.mx, self.my); } $(self.canvas).off('mousemove.fireworks'); }, 1000); self.init = function () { self.canvas = document.createElement('canvas'); self.canvas.width = self.cw = $(window).innerWidth(); self.canvas.height = self.ch = $(window).innerHeight(); self.particles = []; self.partCount = 150; self.fireworks = []; self.mx = self.cw / 2; self.my = self.ch / 2; self.currentHue = 30; self.partSpeed = 5;//5 self.partSpeedVariance = 5;//半径10 self.partWind = 50; self.partFriction = 5; self.partGravity = 1; self.hueMin = 0; self.hueMax = 360; self.fworkSpeed = 4;//4 self.fworkAccel = 10; self.hueVariance = 30; self.flickerDensity = 25; self.showShockwave = true; self.showTarget = false; self.clearAlpha = 25; $(document.body).append(self.canvas); self.ctx = self.canvas.getContext('2d'); self.ctx.lineCap = 'round'; self.ctx.lineJoin = 'round'; self.lineWidth = 1; self.bindEvents(); self.canvasLoop(); self.canvas.onselectstart = function () { return false; }; }; self.createParticles = function (x, y, hue) { var countdown = self.partCount; while (countdown--) { var newParticle = { x: x, y: y, coordLast: [{ x: x, y: y }, { x: x, y: y }, { x: x, y: y } ], angle: rand(0, 360), speed: rand(((self.partSpeed - self.partSpeedVariance) <= 0) ? 1 : self .partSpeed - self.partSpeedVariance, (self.partSpeed + self.partSpeedVariance) ), friction: 1 - self.partFriction / 100, gravity: self.partGravity / 2, hue: rand(hue - self.hueVariance, hue + self.hueVariance), brightness: rand(50, 80), alpha: rand(40, 100) / 100, decay: rand(10, 50) / 1000, wind: (rand(0, self.partWind) - (self.partWind / 2)) / 25, lineWidth: self.lineWidth }; self.particles.push(newParticle); } }; self.updateParticles = function () { var i = self.particles.length; while (i--) { var p = self.particles[i]; var radians = p.angle * Math.PI / 180; var vx = Math.cos(radians) * p.speed; var vy = Math.sin(radians) * p.speed; p.speed *= p.friction; p.coordLast[2].x = p.coordLast[1].x; p.coordLast[2].y = p.coordLast[1].y; p.coordLast[1].x = p.coordLast[0].x; p.coordLast[1].y = p.coordLast[0].y; p.coordLast[0].x = p.x; p.coordLast[0].y = p.y; p.x += vx; p.y += vy; p.y += p.gravity; p.angle += p.wind; p.alpha -= p.decay; if (!hitTest(0, 0, self.cw, self.ch, p.x - p.radius, p.y - p.radius, p.radius * 2, p.radius * 2) || p.alpha < .05) { self.particles.splice(i, 1); } }; }; self.drawParticles = function () { var i = self.particles.length; while (i--) { var p = self.particles[i]; var coordRand = (rand(1, 3) - 1); self.ctx.beginPath(); self.ctx.moveTo(Math.round(p.coordLast[coordRand].x), Math.round(p.coordLast[ coordRand].y)); self.ctx.lineTo(Math.round(p.x), Math.round(p.y)); self.ctx.closePath(); self.ctx.strokeStyle = 'hsla(' + p.hue + ', 100%, ' + p.brightness + '%, ' + p.alpha + ')'; self.ctx.stroke(); if (self.flickerDensity > 0) { var inverseDensity = 50 - self.flickerDensity; if (rand(0, inverseDensity) === inverseDensity) { self.ctx.beginPath(); self.ctx.arc(Math.round(p.x), Math.round(p.y), rand(p.lineWidth, p.lineWidth + 3) / 2, 0, Math.PI * 2, false) self.ctx.closePath(); var randAlpha = rand(50, 100) / 100; self.ctx.fillStyle = 'hsla(' + p.hue + ', 100%, ' + p.brightness + '%, ' + randAlpha + ')'; self.ctx.fill(); } } }; }; self.createFireworks = function (startX, startY, targetX, targetY) { var newFirework = { x: startX, y: startY, startX: startX, startY: startY, hitX: false, hitY: false, coordLast: [{ x: startX, y: startY }, { x: startX, y: startY }, { x: startX, y: startY } ], targetX: targetX, targetY: targetY, speed: self.fworkSpeed, angle: Math.atan2(targetY - startY, targetX - startX), shockwaveAngle: Math.atan2(targetY - startY, targetX - startX) + (90 * ( Math.PI / 180)), acceleration: self.fworkAccel / 100, hue: self.currentHue, brightness: rand(50, 80), alpha: rand(50, 100) / 100, lineWidth: self.lineWidth }; self.fireworks.push(newFirework); }; self.updateFireworks = function () { var i = self.fireworks.length; while (i--) { var f = self.fireworks[i]; self.ctx.lineWidth = f.lineWidth; vx = Math.cos(f.angle) * f.speed, vy = Math.sin(f.angle) * f.speed; f.speed *= 1 + f.acceleration; f.coordLast[2].x = f.coordLast[1].x; f.coordLast[2].y = f.coordLast[1].y; f.coordLast[1].x = f.coordLast[0].x; f.coordLast[1].y = f.coordLast[0].y; f.coordLast[0].x = f.x; f.coordLast[0].y = f.y; if (f.startX >= f.targetX) { if (f.x + vx <= f.targetX) { f.x = f.targetX; f.hitX = true; } else { f.x += vx; } } else { if (f.x + vx >= f.targetX) { f.x = f.targetX; f.hitX = true; } else { f.x += vx; } } if (f.startY >= f.targetY) { if (f.y + vy <= f.targetY) { f.y = f.targetY; f.hitY = true; } else { f.y += vy; } } else { if (f.y + vy >= f.targetY) { f.y = f.targetY; f.hitY = true; } else { f.y += vy; } } if (f.hitX && f.hitY) { self.createParticles(f.targetX, f.targetY, f.hue); self.fireworks.splice(i, 1); } }; }; self.drawFireworks = function () { var i = self.fireworks.length; self.ctx.globalCompositeOperation = 'lighter'; while (i--) { var f = self.fireworks[i]; self.ctx.lineWidth = f.lineWidth; var coordRand = (rand(1, 3) - 1); self.ctx.beginPath(); self.ctx.moveTo(Math.round(f.coordLast[coordRand].x), Math.round(f.coordLast[ coordRand].y)); self.ctx.lineTo(Math.round(f.x), Math.round(f.y)); self.ctx.closePath(); self.ctx.strokeStyle = 'hsla(' + f.hue + ', 100%, ' + f.brightness + '%, ' + f.alpha + ')'; self.ctx.stroke(); if (self.showTarget) { self.ctx.save(); self.ctx.beginPath(); self.ctx.arc(Math.round(f.targetX), Math.round(f.targetY), rand(1, 8), 0, Math.PI * 2, false) self.ctx.closePath(); self.ctx.lineWidth = 0.1; self.ctx.stroke(); self.ctx.restore(); } if (self.showShockwave) { self.ctx.save(); self.ctx.translate(Math.round(f.x), Math.round(f.y)); self.ctx.rotate(f.shockwaveAngle); self.ctx.beginPath(); self.ctx.arc(0, 0, 1 * (f.speed / 5), 0, Math.PI, true); self.ctx.strokeStyle = 'hsla(' + f.hue + ', 100%, ' + f.brightness + '%, ' + rand(25, 60) / 100 + ')'; self.ctx.lineWidth = f.lineWidth*0.1; self.ctx.stroke(); self.ctx.restore(); } }; }; self.bindEvents = function () { $(window).on('resize', function () { clearTimeout(self.timeout); self.timeout = setTimeout(function () { self.canvas.width = self.cw = $(window).innerWidth(); self.canvas.height = self.ch = $(window).innerHeight(); self.ctx.lineCap = 'round'; self.ctx.lineJoin = 'round'; }, 100); }); $(self.canvas).on('mousedown', function (e) { // self.mx = e.pageX - self.canvas.offsetLeft; // self.my = e.pageY - self.canvas.offsetTop; // self.currentHue = rand(self.hueMin, self.hueMax); // self.createFireworks(self.cw / 2, self.ch, self.mx, self.my); // $(self.canvas).on('mousemove.fireworks', function (e) { // self.mx = e.pageX - self.canvas.offsetLeft; // self.my = e.pageY - self.canvas.offsetTop; // self.currentHue = rand(self.hueMin, self.hueMax); // self.createFireworks(self.cw / 2, self.ch, self.mx, self.my); // }); // $(self.canvas).off('mousemove.fireworks'); }); // $(self.canvas).on('mouseup', function (e) { // }); } self.clear = function () { self.particles = []; self.fireworks = []; self.ctx.clearRect(0, 0, self.cw, self.ch); }; self.canvasLoop = function () { requestAnimFrame(self.canvasLoop, self.canvas); self.ctx.globalCompositeOperation = 'destination-out'; self.ctx.fillStyle = 'rgba(0,0,0,' + self.clearAlpha / 100 + ')'; self.ctx.fillRect(0, 0, self.cw, self.ch); self.updateFireworks(); self.updateParticles(); self.drawFireworks(); self.drawParticles(); }; self.init(); } var fworks = new Fireworks(); }); </script> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2020-02-16 python小白学习记录 生产者消费者模型爬取斗图啊网站 (源码有待修改)
2020-02-16 python小白学习记录 selenium的初步学习