【发布时间】:2016-12-24 00:04:17
【问题描述】:
我正在尝试使用 EaselJS 模拟在 spire's 横幅中看到的画布元素。但是我的动画在 chrome 和 firefox 上都很不稳定。任何帮助表示赞赏。 (第一次使用 EaselJS)
我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>EaselJS</title>
<style>
body{
margin: 0;
padding: 0;
overflow: hidden;
}
#spire-canvas{
background: #333;
}
</style>
</head>
<body>
<canvas id="spire-canvas" width="1366" height="768"></canvas>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/EaselJS/0.8.0/easeljs.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js"></script>
<script>
$(document).ready(function(){
//INITIALIZATIONS
var stage,
particles = 10,
fps = 30,
viewportWidth = window.innerWidth,
viewportHeight = window.innerHeight,
circles = [];
function init(){
stage = new createjs.Stage("spire-canvas");
createjs.Ticker.addEventListener("tick", refresh);
createjs.Ticker.setFPS(fps);
console.log("init fired");
}
function refresh(){
for(var i = 0; i < particles; i++){
var circle = new createjs.Shape();
circle.graphics.beginFill('#' + Math.floor(Math.random() * 16777215).toString(16))
.drawCircle(0, 0, (Math.random() * 10));
circle.x = circle.x + Math.random() * viewportWidth;
circle.y = (Math.random() * viewportHeight) + viewportHeight;
circle.alpha = 0.1 + Math.random() * 0.2;
stage.addChild(circle);
circles.push(circle);
};
for(var i = 0; i < circles.length; i++){
var item = circles[i];
var yy = item.y + Math.floor(Math.random() * (viewportHeight - 300)) * -1;
if(item.y < 300){
TweenLite.to(item, 1, {alpha: '0', ease: Power4.easeOut, onComplete: function(){
stage.removeChild(item);
}});
}
TweenLite.to(item, 10, {y: yy});
};
stage.update();
}
init();
});
</script>
</body>
</html>
【问题讨论】:
标签: javascript html5-canvas createjs easeljs gsap