Compatibility with multiple browsers for translucent (Operaiefirefox) _ experience exchange

Source: Internet
Author: User
Compatible with multiple browsers for translucent (Operaiefirefox) Click on a link above to make the image disappear and re-appear by gradually fading in/out. it uses CSS transparency, in CSS you can set the transparency in different ways. to ensure that it works on most browsers we use all three.

Opacity: 0.5;
This one is the official CSS3 method, at the moment it works in newer Mozilla versions.
-Moz-opacity: 0.5;
This one works in older versions of Mozilla and Phoenix/FireBird/FireFox.
-Khtml-opacity: 0.5;
This is used by browsers that use teh KHTML rendering engine, namely Konquerer on Linux and Safari on MacOS.
Filter: alpha (opacity = 50 );
This one works only in MSIE.
There is actually another one:-khtml-opacity: 0.5; works for the browsers Konquerer on Linux and Safari on MacOS. you cocould add it too if you want to support these users. somewhere in the near future most browsers will support CSS3 and opacity: 0.5; shocould work everywhere.

The Code is as follows:


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 = (OPS/100 );
Object. Required opacity = (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 blendimage (pid, imageid, imagefile, millisec ){
Var speed = Math. round (millisec/100 );
Var timer = 0;

// Set the current image as background
Document. getElementById (pid). style. backgroundImage = "url (" + document. getElementById (imageid). src + ")";

// Make image transparent
ChangeOpac (0, imageid );

// Make new image
Document. getElementById (imageid). src = imagefile;

// Fade in image
For (I = 0; I <= 100; I ++ ){
SetTimeout ("changeOpac (" + I + ", '" + imageid + "')", (timer * speed ));
Timer ++;
}
}

Function currentOpac (id, opacEnd, millisec ){
// Standard opacity is 100
Var currentopps = 100;

// If the element has an opacity set, get it
If (document. getElementById (id). style. opacity <100 ){
CurrentOpac = document. getElementById (id). style. opacity * 100;
}

// Call for the function that changes the opacity
Opacity (id, currentOpac, opacEnd, millisec)
}


More references
Http://www.brainerror.net/scripts_js_blendtrans.php
Http://realazy.org/blog/2006/03/21/ie-firefox-opera-alpha-transparency/ href = "http://realazy.org/blog/2006/03/21/ie-firefox-opera-alpha-transparency/" target = _ blank> http://realazy.org/blog/2006/03/21/ie-firefox-opera-alpha-transparency/
Http://alistapart.com/stories/pngopacity/ href = "http://alistapart.com/stories/pngopacity/" target = _ blank> http://alistapart.com/stories/pngopacity/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.