我希望只用我的鼠标移动功能旋转每一秒的矩形,我做错了什么? 我怎样才能进行变换,以便高度和旋转每一秒都会改变?我用if(i%2 == 0){}
试了一下function modifyRectangles(mouseX,mouseY) {
for (var i = 0; i < myRects.length; i++) {
// var sx = 1;
var h = myRects [i].getAttribute("height");
if ( i % 2 == 0){
var angle = (mouseY) + 45;
var sy =(mouseY/10) + 0.5;
}
angle -= 45;
myRects[i].setAttribute("transform", "translate(" + x + ", 100), rotate("+angle+"), scale(1, " + sy + ")");
}
}
答案 0 :(得分:1)
只删除条件,而不删除括号内的代码:
if ( i % 2 == 0){...}
然后改变你的for循环:
for (var i = 0; i < myRects.length; i +=2) {...