Google Chrome JavaScript Fade: style.opacity and setTimeout -
i have javascript script fade element.
the gist this:
function fade() { if (cat.style.opacity > 0) { // decrease opacity cat.style.opacity -= 0.1; // call fade again in fraction of second settimeout( fade, 60 ); } else { cat.style.visibility = "hidden"; } }
( full code here http://xahlee.info/js/js_fadeout.html , javascript code here: http://xahlee.info/js/js_fadeout.js )
in google chrome, doesn't fade completely. seems loop stuck , style.opacity never reaches 0.
on stackoverflow, seems google chrome bug post year ago, never confirmed.
seems strange, major bug. know why doesn't work in google chrome?
this appears precision issue. can around pretty using .tofixed
precision need.
cat.style.opacity = (cat.style.opacity - 0.1).tofixed(2);
Comments
Post a Comment