[Javascript] Smooth change of div

Peter Lauri lists at dwsasia.com
Thu Jun 8 02:27:17 CDT 2006


Hi group,

I use this function to swap between two DIV's. Ok it is maybe not perfect
code, but it works. This just hides id1 and shows id2 or the opposite. Is
there any easy way to extend this so that the DIV's slowly disappears and
then the otherone slowly show up (not to slow, but just like dropdown)? I
was thinking about using the value of the height and decrement and increment
the height and with that create the dropdown. But that feels like cheating,
or maybe not? Is there anyone with a hint in what direction to go?

function swapBetween(id1, id2) {
    var el = document.getElementById (id1);
    var isVisible = (el.style.visibility == "visible") ? true : false;
    
    var e2 = document.getElementById (id2);
        
    if(isVisible) {
    	el.style.visibility = "hidden";
    	el.style.display = "none";
    	e2.style.visibility = "visible";
    	e2.style.display = "inline";
    } else {
    	e2.style.visibility = "hidden";
    	e2.style.display = "none";
    	el.style.visibility = "visible";
    	el.style.display = "inline";    }
}

Best regards,
Peter Lauri





More information about the Javascript mailing list