Transparent HTML nodes without affecting content





4
Date Submitted Wed. Nov. 28th, 2007 8:14 AM
Revision 1 of 1
Helper HRCerqueira
Tags HTML | JavaScript
Comments 1 comments
This code allows you to set the "opcity" style attribute on a element without affecting it's content.

Just call the function for a specific element or to all elements of a given classname after the document loads.

Examples and advanced usage here...


function applyTransparencyHack(element) {
        //create the background container
        var backContainer = $new('DIV');
 
        //apply the same location, dimension and background properties of the element
        backContainer.style.width = element.style.width;
        backContainer.style.height = element.style.height;
        backContainer.style.background = element.style.background;
        backContainer.style.opacity = element.style.opacity;
        backContainer.style.position = 'absolute';
        backContainer.style.top = element.style.top;
        backContainer.style.left = element.style.left;
 
        //remove background definitions from the element
        element.style.background = ''
        element.style.opacity = 1;
 
        //now append the background container before the element
        element.appendBefore(backContainer);
}

 

Hernāni Cerqueira

www.hrcerqueira.com

Comments

Comments Adjustments, Prototype
Fri. Dec. 14th, 2007 5:10 PM    Helper Fordiman

Voting

Votes Down