Fading in HTML text in JavaScript -


i've been trying text fade in opacity 0 100, can't seem work right. credits person original fadeout version.

here's code...

fadein = function(id, speed) {     var s = document.getelementbyid(id).style;     s.opacity = 0;     (function fade() {(s.opacity+= .1)<100?s.display="inline":settimeout(fade,speed)})(); } 

i think there 2 problems, 1 opacity values vary 0...1 not 0..100 when opacity 1 need stop loop.

second, s.opacity returns string, since using + operator need convert value string else string concatenation performed

fadein = function(id, speed) {    var s = document.getelementbyid(id).style;    s.opacity = 0;    (function fade() {      (s.opacity = +s.opacity + .1) >= 1 ? s.display = "inline" : settimeout(fade, speed)    })();  }    fadein('s', 500)
<div id="s">asdfsadf</div>


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -