0
    var faderout = function(){
    if(foo.style.opacity>0){
    foo.style.opacity -= 0.1;
    var t = setTimeout(faderout,100);
    }
    else if(foo.style.opacity == 0){
    o = true;
    clearTimeout(t);
}

I can't get the opacity to exact 0, I just get it to 0.1000000004, any one know why i dont get it to 0?

Akshay
  • 3,361
  • 1
  • 21
  • 19
  • 1
    That is how floating point numbers behave.. http://stackoverflow.com/questions/1458633/elegant-workaround-for-javascript-floating-point-number-problem – Sushanth -- Aug 11 '13 at 21:46
  • Why not lose the 'else if' and replace with 'else'. Also, I'd suggest just copying the jQuery source for the fadeOut() function. No need to reinvent the wheel. – David Gilbertson Aug 11 '13 at 22:08

1 Answers1

0

Try foo.style.opacity = Math.max(foo.style.opacity - 0.1, 0)

disatisfieddinosaur
  • 1,502
  • 10
  • 15