Date.parse

JavaScript:

 

Date.parse(),一个参数,参数类型是 JavaScript 中的 Date 类型。

返回值 : 得到一个 Unix 时间戳,比如说,1470993235000,这种东西。

注意 : 我们知道,最后三位是毫秒数,但是,使用Date.parse得到的时间戳,最后三位永远是 000 。也就是说,Date.parse 只能精确到 秒级, 而不能精确到 毫秒。

posted on 2016-08-12 17:19  一页天书不分说 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/onebook/p/5765760.html

### HTML 网页代码实现过年烟花效果 为了创建具有春节氛围的烟花效果,可以采用HTML5 `Canvas` 和 JavaScript 结合的方式。下面是一个简单版本的烟花爆炸动画示例: #### 完整HTML文件结构如下所示: ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>新年快乐 - 烟花秀</title> <style> body { margin: 0; overflow:hidden;background-color:#000;} canvas { display:block } </style> </head> <body> <canvas id="fireworks"></canvas> <script> class Particle { constructor(x, y) { this.x = x; this.y = y; this.color = 'hsl(' + Math.random() * 360 + ', 100%, 70%)'; this.size = Math.random() * 4 + 1; this.speedX = (Math.random() - .5) * 10; this.speedY = (Math.random() - .5) * 10; this.alpha = 1; } update(ctx) { ctx.globalAlpha = this.alpha -= 0.01; ctx.fillStyle = this.color; ctx.beginPath(); ctx.arc(this.x += this.speedX, this.y += this.speedY, this.size, 0, Math.PI * 2); ctx.fill(); if (this.alpha <= 0) particles.splice(particles.indexOf(this), 1); } } let canvas = document.getElementById('fireworks'); let context = canvas.getContext('2d'); canvas.width = window.innerWidth; canvas.height = window.innerHeight; window.addEventListener('resize', function () { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }); function createFirework(event) { let mouseX = event.clientX || event.touches[0].clientX; let mouseY = event.clientY || event.touches[0].clientY; for (var i = 0; i < 100; i++) { particles.push(new Particle(mouseX, mouseY)); } } document.body.addEventListener('click', createFirework); let particles = []; function animate() { requestAnimationFrame(animate); context.clearRect(0, 0, innerWidth, innerHeight); for (let particle of particles) { particle.update(context); } } animate(); </script> </body> </html> ``` 此段脚本定义了一个名为Particle的对象来表示单个火花粒子,并设置了其属性如位置、颜色、大小以及速度等[^1]。 页面加载完成后会监听窗口尺寸变化事件以便调整画布大小适应不同设备屏幕;同时绑定了鼠标点击事件,在用户点击处生成一组随机分布的小颗粒模拟烟花的过程[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值