On Feb 10, 9:47 pm, Tuxedo <tux...@mailinator.net> wrote:
> My question is, how can the loop be done, starting from no opacity to full
> opacity, in for example 100 increments over a period of one second, by
> setting/resetting the opacity and decimal values until the loop is complete?
Here is the code which is at work at <http://beta.quomodo.com> (when
you edit a note all others become half-transparent). I edited it a bit
(for your purpose), so I may have introduced some bugs. On the other
hand, I provide the additional stuff for IE6.
Instructions for use: call qsn_dim with div = the element concerned,
dimtarget = the opacity value you want to reach
var nsteps = 100
var duration = 1000 // thousandths of a seconds, that is 1 second
function qsn_dim ( div , dimtarget ) {
div.dimtarget = dimtarget ;
do_qsn_dim( div ) ;
}
function do_qsn_dim( div ) {
if ( ! div.style.opacity ) div.style.opacity = "1" ;
var opa = parseFloat ( div.style.opacity ) ;
if ( div.dimtarget > opa ) {
opa = opa + 1.0/nsteps ;
if ( opa > div.dimtarget ) opa = div.dimtarget ;
} else {
opa = opa - 1.0/nsteps ;
if ( opa < div.dimtarget ) opa = div.dimtarget ;
}
div.style.opacity = "" + opa ;
div.style.filter = "alpha(opacity=" + Math.round ( 100 * opa ) +
")" ;
if ( opa != div.dimtarget ) setTimeout ( "do_qsn_dim ( '" + x +
"' )" , duration/nsteps ) ;
} // opacity: "0.5" ; filter: alpha(opacity=50)