我有function handleKeyDown(e) {
if (!e) {
var e = window.event;
}
if (e.keyCode == '1'.charCodeAt(0)) {
var imagearray = [ChickenMale3Container, ChickenMale2Container, ChickenMaleContainer];
imagearray.forEach(function (element) {
rotateanscleElement(element);
});
}
function rotateanscleElement(element) {
createjs.Tween.get(element, {
loop: false
})
.to({
regY: element.height / 2,
regX: element.width / 2,
x: element.x + 138,
y: element.y + 133,
rotation: 0
}, 1)
.to({
scaleX: 0.7,
scaleY: 0.7
}, 1000, createjs.Ease.bounceOut)
.to({
regY: element.height / 2,
regX: element.width / 2,
rotation: 360
}, 1000)
.to({
scaleX: 1,
scaleY: 1
}, 500, createjs.Ease.bounceOut)
.to({
regY: 0,
regX: 0,
x: element.x,
y: element.y,
rotation: 0
}, 1)
}
函数,onpress它执行补间函数。在这段代码中,我正在补充数组中的多个对象:
forEach
我想要的是将数组和if
函数放在补间函数中,而不是放在 //1-225
threshold = 100;
//Get Canvas Element Data
imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height);
data = imageData.data;
//RGB
color = [120, 82, 31, 1];
for (var i = 0, n = data.length; i <n; i += 4) {
if(data[i] === color[0] && data[i+1] === color[1] && data[i+2] === color[2]){
data[i+3] = 1;
}
}
context.putImageData(imageData, 0, 0);
条件中。如何进行更多代码优化呢?
答案 0 :(得分:0)
if (e.keyCode=='6'.charCodeAt(0)) {
multirotateanscleElement();
}
function multirotateanscleElement(element) {
var imagearray = [ChickenMale3Container,ChickenMale2Container,ChickenMaleContainer];
imagearray.forEach(function(element) {
createjs.Tween.get(element, {loop: false})
.to({regY:element.height/2, regX:element.width/2,x:element.x+138,y:element.y+133,rotation: 0}, 0)
.to({scaleX: 0.7, scaleY: 0.7},500, createjs.Ease.bounceOut)
.to({regY:element.height/2, regX:element.width/2,rotation:360}, 500)
.to({scaleX: 1, scaleY: 1}, 500, createjs.Ease.bounceOut)
.to({regY:0, regX:0,x:element.x,y:element.y,rotation: 0}, 0)
.to({regY:element.height/2, regX:element.width/2,x:element.x+138,y:element.y+133,rotation: 360}, 0)
.to({scaleX: 0.7, scaleY: 0.7},500, createjs.Ease.bounceOut)
.to({regY:element.height/2, regX:element.width/2,rotation:0}, 500)
.to({scaleX: 1, scaleY: 1}, 500, createjs.Ease.bounceOut)
.to({regY:0, regX:0,x:element.x,y:element.y,rotation: 0}, 0)
});