fadeIn and fadeOut in javascript -


i'm trying write own animations using javascript.

i wrote function fadein() below, changes display property followed change in value of opacity. doesn't seem working.

what doing wrong?

function fadein(obj, defdisp) {     obj.style.opacity = 0;     obj.style.display = defdisp;     var opval = 0;     while (opval < 1) {         obj.style.opacity = opval;         opval += 0.1;     } } 

defdisp = default value display property

without timing interval, execute fast see it. while loop, without timeout feature, execute in far less second, , won't see happen. it's asking computer count 10, in less millisecond.

try using settimeout

http://www.w3schools.com/jsref/met_win_settimeout.asp

while(opval < 1) {     settimeout(function(){          obj.style.opacity = opval;         opval += 0.1;     }, 3000); } 

alter timer (3000 in case) makes fade work you. every 1000 1 second , loop runs 10 times, in case 30 seconds, slow.

i stick css transition however, tend render better on browsers.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -