function popupGrowStage3() {
if (popupContentContainer.style.opacity < 1) {
popupContentContainer.style.opacity+= 0.01;
setTimeout(popupGrowStage3, 1000 / 60);
alert(popupContentContainer.style.opacity);
} else {
isPopupShowing = 1;
}
}
popupGrowStage3();
以上代码似乎每次都不会向不透明度添加0.01。警报只是说0.01。为什么要这样做?
popupContentContainer.style.width = popup.style.width;
popupContentContainer.style.height = popup.style.height;
popupContentContainer.style.backgroundColor = "#111111";
popupContentContainer.style.opacity = 0;
popup.appendChild(popupContentContainer);
此代码在此之前
答案 0 :(得分:1)
popupContentContainer.style.opacity
的类型是字符串。因此,当您使用字符串执行+=
时,结果将是连接的字符串。
对于Ex:
var a = '2';
a += 2; //results '22'
popupContentContainer.style.opacity+= 0.01;
popupContentContainer.style.opacity = parseFloat(popupContentContainer.style.opacity) + 0.01;