<script>
function scale(obj) {
obj.style.left = "10px";
obj.style.top = "20px";
for(var i=2;i<5;i++){
obj.style.transform="scale("+i+",1)";
}
}
</script>
이 부분 틀린건가요?ㅜㅜ 양쪽으로 한번만 늘어나고 더 이상 늘어나지 않네요ㅠㅠ
<script>
function scale(obj) {
obj.style.left = "10px";
obj.style.top = "20px";
for(var i=2;i<5;i++){
obj.style.transform="scale("+i+",1)";
}
}
</script>
이 부분 틀린건가요?ㅜㅜ 양쪽으로 한번만 늘어나고 더 이상 늘어나지 않네요ㅠㅠ
for(var i=2;i<5;i++){
obj.style.transform="scale('"+i+",1)";
}
즉 루프의 최종 결과는 다음 결과가 될 것입니다. 즉 옆으로 4배 길어난 모양을 출력하도록 스타일을 지정한 것입니다.
obj.style.transform="scale("+4+",1)"; -> obj.style.transform="scale(4,1)";
그러므로 항상 옆으로 4배 길어난 모양으로만 그리게 되는 거죠.
QnA 131의 답을 참고하고, for 문을 쓸 것이 아니라.
전역 변수 i=1로 설정하고
클릭할 때마다 i 값을 증가시키도록 해야 합니다.