最近,在教学生使用JS的基本操作,为了练习JS的基本作用,特地写了一个喷泉效果,代码如下:
页面代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script src="js/particle.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css">
body{
margin: 0px;
}
</style>
</head>
<body>
</body>
</html>
Particle.js代码如下:
window.onload = function(){
// 创建一个画布对象
var canvas = document.createElement("canvas");
// 设置大小和颜色
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.backgroundColor = "#333333";
// 将画布放置到body里
document.body.a