javascript quandry

    Date: 03/19/08 (Web Development)    Keywords: java

    so there are a bunch of spans, each with display:none, and opacity:0 as properties. I'm trying to write a series of functions that will toggle the span to display:block, and then gradually fade the span into view, wait a few seconds, and then fade it back out to opacity:0, and then hide it again before moving onto the next span.

    The Javascript

    shiftopacity.js

    function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
    for(i = opacStart; i >= opacEnd; i--) {
    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
    timer++;
    }
    } else if(opacStart < opacEnd) {
    for(i = opacStart; i <= opacEnd; i++)
    {
    setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
    timer++;
    }
    }
    }

    //change the opacity for different browsers
    function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
    }


    function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {

    opacity(id, 0, 100, millisec);

    } else {

    opacity(id, 100, 0, millisec);

    }
    }

    function toggleLayer(whichLayer)
    {
    var elem, vis;
    if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
    else if( document.all ) // this is the way old msie versions work
    elem = document.all[whichLayer];
    else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
    vis = elem.style;
    // if the style.display value is blank we try to figure it out here
    if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
    vis.display = (vis.display==''||vis.display=='block')?'none':'block';
    }



    you can check out the HTML portion of the code at jeffmdemers.com


    Thanks in advance, this has been driving me crazy!

    Source: http://community.livejournal.com/webdev/471288.html

« Xoops? || Table help? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home