<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<!-- 注意:style和script都包含在body内部,否则会导致代码无样式效果以及js事件无法实现 -->
<body>
<div id="jsi-particle-container" class="container">
<!-- 创建画布 -->
<canvas width="100%" height="100%" style="align:center;"></canvas><!--canvas标签定义图形,必须使用脚本来绘制图形-->
</div>
<style>
html,body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
/*overflow属性指定如果内容溢出一个元素的框,会发生什么 其属性值hidden表示内容会被修建,并且其余内容是不可见的*/
/* overflow属性值:
visible 默认值,内容不会被修剪,会呈现在元素框之外
hidden 内容会被修剪,并且其余内容是不可见的
scroll 内容会被修剪,但是浏览器会显示滚动条以便查看其他内容
auto 若内容被修剪,则浏览器会显示滚动条
inherit 规定应该从父元素继承overflow属性的值
注意:overflow属性只工作于指定高度的块元素上
*/
}
.container{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #000000;
}
</style>
<script>
//绘制图形
var RENDERER = {
PARTICLE_COUNT : 1000,
PARTICLE_RADIUS : 1,
MAX_ROTATION_ANGLE : Math.PI / 60,
TRANSLATION_COUNT : 10000,
//函数体汇总
init : function(strategy){
this.setParameters(strategy);
this.createParticles();
this.setupFigure();
this.reconstructMethod();
this.bindEvent();
this.drawFigure();
},
//窗口响应事件,图形大小控制
setParameters : function(strategy){
this.$window = $(window);
//调用html中的样式
this.$container = $('#jsi-particle-container');
this.width = this.$container.width();
this.height = this.$container.height();
this.$canvas = $('<canvas />').attr({width : this.width, height : this.height}).appendTo(this.$container);
this.context = this.$canvas.get(0).getContext('2d');//2D动画
th
JQ动态粒子效果
最新推荐文章于 2024-07-08 10:04:44 发布