许多颜色选择后,动画的表现和速度非常慢
Performance and speed of animation is very slow after many colours selection
我用html canvas和一个颜色选择器制作了一个动画,你可以在其中改变动画的两种颜色,但是如果我多次改变颜色,我的动画播放速度就会很慢。如何解决这个问题?
var canvas, stage, exportRoot;
var colorArray = ["#f4ed94", "#eef5db", "#c7efcf", "#a9d18e", "#78cbcf",'
"#5eb3d6", "#bdd7ee", "#af90a9", "#ffc7df", "#ff5a5f", "#e88873",
"#c4c4c4", "#ffffff", "#6e6460", "#464647"];
function init() {
canvas = document.getElementById("canvas");
handleComplete("", "");
}
//for Giftbox
//When Giftbox color change slider is dragged
function giftRangeChange(value) {
var newValue = parseInt(value);
handleComplete(colorArray[newValue], "");
}
//When Giftbox color box is clicked
function giftColourClick(value) {
handleComplete(colorArray[value], "");
console.log(document.getElementById("gift-range").value);
document.getElementById("gift-range").value = value;
}
//for ribbon
//When ribbon color change slider is dragged
function ribbonRangeChange(value) {
var newValue = parseInt(value);
handleComplete("", colorArray[newValue]);
}
//When ribbon color box is clicked
function ribbonColourClick(value) {
handleComplete("", colorArray[value]);
document.getElementById("ribbon-range").value = value;
}
function handleComplete(box, ribbon) {
if (box !== "") {
lib.properties.boxColor = box;
}
if (ribbon !== "") {
lib.properties.ribbonColor = ribbon;
}
exportRoot = new lib.gifbox();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.enableMouseOver();
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
(function(isResp, respDim, isScale, scaleType) {
var lastW, lastH, lastS = 1;
window.addEventListener('resize', resizeCanvas);
resizeCanvas();
function resizeCanvas() {
var w = lib.properties.width,
h = lib.properties.height;
var iw = window.innerWidth,
ih = window.innerHeight;
var pRatio = window.devicePixelRatio || 1,
xRatio = iw / w,
yRatio = ih / h,
sRatio = 1;
if (isResp) {
if ((respDim == 'width' && lastW == iw) || (respDim == 'height' && lastH == ih)) {
sRatio = lastS;
} else if (!isScale) {
if (iw < w || ih < h)
sRatio = Math.min(xRatio, yRatio);
} else if (scaleType == 1) {
sRatio = Math.min(xRatio, yRatio);
} else if (scaleType == 2) {
sRatio = Math.max(xRatio, yRatio);
}
}
canvas.width = w * pRatio * sRatio;
canvas.height = h * pRatio * sRatio;
canvas.style.width = w * sRatio + 'px';
canvas.style.height = h * sRatio + 'px';
stage.scaleX = pRatio * sRatio;
stage.scaleY = pRatio * sRatio;
lastW = iw;
lastH = ih;
lastS = sRatio;
}
})(false, 'both', false, 1);
}
输入链接描述
我设法解决了这个问题。我只是使用removeEventListener编辑了函数handleccomplete (box, ribbon),然后清除了舞台,所以我删除了以前的颜色值。谢谢你的其他解决方案。
function handleComplete(box, ribbon) {
if (box !== "") {
lib.properties.boxColor = box;
}
if (ribbon !== "") {
lib.properties.ribbonColor = ribbon;
}
createjs.Ticker.removeEventListener("tick", stage);
exportRoot = new lib.gifbox();
stage = new createjs.Stage(canvas);
stage.clear();
stage.addChild(exportRoot);
stage.enableMouseOver();
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
相关文章:
- CS5隐藏图层的速度非常慢
- 简单的dart网页应用程序在IE上添加按钮的速度非常慢
- 启动网站时,页面和图像加载速度非常慢
- 太多的音频标签使我的网站加载速度非常慢.有没有解决方案
- 生成图像的速度非常快
- $cordovaContacts加载速度非常慢
- IEDriverServer 发送密钥的速度非常慢 - JavaScript 替代建议
- Facebook推荐/最近的活动挂在浏览器上,速度非常慢
- jQuery:当重复调用时,重绘函数的速度非常慢
- html5sql.js在安卓蜂窝和ICS中的插入速度非常慢
- IE8(javascript):在SELECT元素中加载大量选项的速度非常慢
- CanvasRenderingContext2D.drawImage()在大画布上的Chrome中速度非常慢
- 安卓设备上的JavaScript/HTML/CSS应用程序-速度非常慢
- 使得音频文件在线播放速度非常慢
- 在javascript中切换时,Chrome应用样式表的速度非常慢
- 我的Node.js应用程序的反应速度非常慢
- 许多颜色选择后,动画的表现和速度非常慢
- Javascript在Ajax中的加载速度非常慢
- couchDB的过滤速度非常慢,即使使用erlang也是如此
- 当 float:left 在 EE2 中使用一些繁重的 JavaScript 时,滚动速度非常慢(浏览器原生)