jquery实现鱼跳出水面动画效果代码
代码语言:html
所属分类:动画
代码描述:jquery实现鱼跳出水面动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html lang="en"><head>
<meta charset="UTF-8">
<style>
html, body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
.container{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
background-color: #FFFFFF;
}
</style>
</head>
<body>
<div id="jsi-flying-fish-container" class="container"></div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/jquery-3.2.1.min.js"></script>
<script>
var RENDERER = {
POINT_INTERVAL: 5,
FISH_COUNT: 3,
MAX_INTERVAL_COUNT: 50,
INIT_HEIGHT_RATE: 0.5,
THRESHOLD: 50,
init: function () {
this.setParameters();
this.reconstructMethods();
this.setup();
this.bindEvent();
this.render();
},
setParameters: function () {
this.$window = $(window);
this.$container = $('#jsi-flying-fish-container');
this.$canvas = $('<canvas />');
this.context = this.$canvas.appendTo(this.$container).get(0).getContext('2d');
this.points = [];
this.fishes = [];
this.watchIds = [];
},
createSurfacePoints: function () {
var count = Math.round(this.width / this.POINT_INTERVAL);
this.pointInterval = this.width / (count - 1);
this.points.push(new SURFACE_POINT(this, 0));
for (var i = 1; i < count; i++) {
var point = new SURFACE_POINT(this, i * this.pointInterval),
previous = this.points[i - 1];
point.setPreviousPoint(previous);
previous.setNextPoint(point);
this.points.push(point);
}
},
reconstructMethods: function () {
this.watchWindowSize = this.watchWindowSize.bind(this);
this.jdugeToStopResize = this.jdugeToStopResize.bind(this);
this.startEpicenter = this.startEpicenter.bind(this);
this.moveEpicenter = this.moveEpicenter.bind(this);
this.reverseVertical = this.reverseVertical.bind(this);
this.render = this.render.bind(this);
},
setup: function () {
this.points.length = 0;
this.fishes.length = 0;
this.watchIds.length = 0;
this.intervalCount = this.MAX_INTERVAL_COUNT;
this.width = this.$container.width();
this.height = this.$container.height();
this.fishCount = this.FISH_COUNT * this.width / 500 * this.height / 500;
this.$canvas.attr({ width: this.width, height: this.height });
this.reverse = false;
this.fishes.push(new FISH(this));
this.createSurfacePoints();
},
watchWindowSize: function () {
this.clearTimer();
this.tmpWidth = this.$window.width();
this.tmpHeight = this.$window.height();
this.watchIds.push(setTimeout(this.jdugeToStopResize, this.WATCH_INTERVAL));
},
clearTimer: function () {
while (this.watchIds.length > 0) {
clearTimeout(this.watchIds.pop());
}
},
jdugeToStopResize: function () {
var width = this.$window.width(),
height = this.$window.height(),
stopped = width == this.tmpWidth && height == this.tmpHeight;
this.tmpWidth = width;
this.tmpHeight = height;
if (stopped) {
this.setup();
}
},
bindEvent: function () {
this.$window.on('resize', this.watchWindowSize);
this.$container.on('mouseenter', this.startEpicenter);
this.$container.on('mousemove', this.moveEpicenter);
this.$container.on('click', this.reverseVertical);
},
getAxis: function (event) {
var offset = this.$container.offset();
return {
x: event.clientX - offset.left + this.$window.scrollLeft(),
y: event.clientY - offset.top + this.$window.scrollT.........完整代码请登录后点击上方下载按钮下载查看
网友评论0