Js将for循环中的i+=2
读为
4002
而不是添加应该为2+400
的{{1}}。增量不在引号中,所以我不知道为什么这样做。
402
function move(evt) {
var text = evt.target;
var currentSize = text.getAttribute("font-size");
var timer = 0;
for (let i = currentSize; i < 11000; i += 2) {
function changeText() {
text.setAttribute("font-size", i);
console.log(i);
}
setTimeout((changeText), timer);
timer = timer + 40;
}
.container {
background-color: yellow;
z-index: 7;
height: 100%;
width: 100%;
position: absolute;
opacity: .5;
}
答案 0 :(得分:0)
就像@Carcigenicate和@collapsar在评论中所说的那样;尝试将currentSize解析为数字。
function move(evt) {
var text = evt.target;
var currentSize = parseInt(text.getAttribute("font-size")); // <- Parse the currentSize as int
var timer = 0;
for (let i = currentSize; i < 11000; i += 2) {
function changeText() {
text.setAttribute("font-size", 58);
console.log(i);
}
setTimeout((changeText), timer);
timer = timer + 40;
}
}