最新下载
jQuery超酷动态弹出表单 jQuery超酷动态弹出表单网页特效
24小时阅读排行榜
- 1 javascript拖放功能如何实现_原生drag和drop api怎样使用【教程】
- 2 Golang中频繁创建对象如何优化_Golang对象复用与内存优化
- 3 PHP 中 mktime() 函数参数类型错误的修复指南
- 4 PHP 中 mktime() 函数因参数类型严格校验导致的致命错误详解
- 5 PHP中mktime()函数调用错误的修复方法
- 6 如何在动态生成表单时,通过表单外部按钮(如导航栏按钮)触发提交?
- 7 WordPress 中 admin_notices 通知显示位置异常的解决方案
- 8 WordPress 后台通知(admin_notices)显示错位的解决方案
- 9 Pyomo教程:如何在优化模型中为每个请求动态定义时间窗口并施加能量约束
- 10 如何在 Go 中对结构体切片进行降序排序
- 11 WordPress 中 admin_notices 通知显示错位的解决方案
- 12 WordPress 插件中实现 CAPTCHA 图像生成的正确方法
- 13 如何在 WordPress 中随机显示 20 名订阅用户(含头像)
- 14 Pyomo教程:如何为动态时间窗口内的请求构建条件能量约束
- 15 JavaScript 中从数组构建分层随机三叉树的完整教程
最新教程
-
- Node.js 教程
- 16389 2025-08-28
-
- CSS3 教程
- 1547147 2025-08-27
-
- Rust 教程
- 23488 2025-08-27
-
- Vue 教程
- 25913 2025-08-22
-
- PostgreSQL 教程
- 22415 2025-08-21
-
- Git 教程
- 9352 2025-08-21
html5 canvas线条下落动画特效是一款跟下雨有点相似的线条下落动画效果。
(function(){
var c = document.getElementById("c"),
ctx = c.getContext("2d");
c.width = innerWidth;
c.height = innerHeight;
var lines = [],
maxSpeed = 5,
spacing = 5,
xSpacing = 0,
n = innerWidth / spacing,
colors = ["#3B8686", "#79BD9A", "#A8DBA8", "#0B486B"],
i;
for (i = 0; i < n; i++){
xSpacing += spacing;
lines.push({
x: xSpacing,
y: Math.round(Math.random()*c.height),
width: 2,
height: Math.round(Math.random()*(innerHeight/10)),
speed: Math.random()*maxSpeed + 1,
color: colors[Math.floor(Math.random() * colors.length)]
});
}
function draw(){
var i;
ctx.clearRect(0,0,c.width,c.height);
for (i = 0; i < n; i++){
ctx.fillStyle = lines[i].color;
ctx.fillRect(lines[i].x, lines[i].y, lines[i].width, lines[i].height);
lines[i].y += lines[i].speed;
if (lines[i].y > c.height)
lines[i].y = 0 - lines[i].height;
}
requestAnimationFrame(draw);
}
draw();
}());
