我有一个简单的间隔,每次减去 0.1。但是数字序列在 3 次迭代后变得很奇怪......这就是我所拥有的:
function transition_opacity(div_id,opacity){
opacity = 1; //temporary test
var IntervId = setInterval(process_transition,30);
function process_transition(){
console.log(opacity); //check the value
opacity = opacity - 0.1
div_id.style.opacity = opacity;
if(opacity < 0.0){
rmv_div(div_id);
clear();
}
}
function clear(){
clearInterval(IntervId);
}
}
控制台日志显示以下值opacity
:
1
0.9
0.8
0.7000000000000001
0.6000000000000001
0.5000000000000001
0.40000000000000013
0.30000000000000016
0.20000000000000015
0.10000000000000014
1.3877787807814457e-16
为什么它会做这个疯狂的数字序列=/对我来说似乎没有意义......它可以正常工作到 0.8