首页 技术 正文
技术 2022年11月6日
0 收藏 597 点赞 350 浏览 1084 个字

HTML 和 JavaScript 实现飘花的效果,也不算花,就是有悬浮物飘下来,和下雪似的。

也是不需要图片和其他的 js 脚本做辅助,其实已经全写在 HTML 文件中了。

<html>
<head>
<title>飘花效果</title>
</head>
<body><canvas id="christmasCanvas"
style="top: 0px; left: 0px; z-index: 5000; position: fixed; pointer-events: none;"></canvas>
<script>
var snow = function () {
var b = document.getElementById("christmasCanvas"), a = b.getContext("2d"), d = window.innerWidth,
c = window.innerHeight;
b.width = d;
b.height = c;
for (var e = [], b = 0; b < 70; b++) {
e.push({x: Math.random() * d, y: Math.random() * c, r: Math.random() * 4 + 1, d: Math.random() * 70})
}
var h = 0;
window.intervral4Christmas = setInterval(function () {
a.clearRect(0, 0, d, c);
a.fillStyle = "rgba(255, 255, 0, 0.6)";
a.shadowBlur = 5;
a.shadowColor = "rgba(255, 255, 255, 0.9)";
a.beginPath();
for (var b = 0; b < 70; b++) {
var f = e[b];
a.moveTo(f.x, f.y);
a.arc(f.x, f.y, f.r, 0, Math.PI * 2, !0)
}
a.fill();
h += 0.01;
for (b = 0; b < 70; b++) {
if (f = e[b], f.y += Math.cos(h + f.d) + 1 + f.r / 2, f.x += Math.sin(h) * 2, f.x > d + 5 || f.x < -5 || f.y > c) {
e[b] = b % 3 > 0 ? {x: Math.random() * d, y: -10, r: f.r, d: f.d} : Math.sin(h) > 0 ? {
x: -5,
y: Math.random() * c,
r: f.r,
d: f.d
} : {x: d + 5, y: Math.random() * c, r: f.r, d: f.d}
}
}
}, 70)
}
snow();
</script></body>
</html>

就是下面的效果,有黄色的小圈圈掉下来。能看清吧?

    HTML 和 JavaScript 实现飘花的效果

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,999
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,357
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,140
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848