View Full Version : Stop Firefox from Reading This

01-18-2006, 06:37 PM
function loadMenu_FadeIn(){
menuOpacity += 10;
document.getElementById('MenuDiv').style.filter = "alpha(opacity: "+menuOpacity+")";

if( menuOpacity<100 ){
setTimeout('loadMenu_FadeIn()', 50);

This filter fade will only work in IE. So unless someone knows of a way to do this in FF, how can I make FF ignore this code? (That way it dosn't spit junk into the Javascript Consol)

Thanks guys.

01-18-2006, 06:53 PM
Mozilla uses -moz-opacity for opacity, so really you should be detecting IE and Firefox, and then every other browser (using 'opacity'), and provide each one with the correct function.


01-18-2006, 07:51 PM
The page you linked to states at the top that it is out of date, and not use it.
Also, the functions listed on it error on all browsers.

01-19-2006, 09:08 PM
This site (http://www.brainerror.net/scripts_js_blendtrans.php) has a good review of the current opacity attributes that different browsers use. There are two ways to actually test which to use. The first would be to test the existance of each property before attempting to change it:

object.style.opacity=opacityStrength / 100;
} else {
object.style.filter = "alpha(opacity:"+ opacityStrength+")";

The other way is just to assign each without testing before. You'd basically cause each object to be a little bigger since it would hold a property for each browser, but only the browser-specific attribute would actually be used when displaying the page (this is the procedure that the link used).

One last thing to note: IE's opacity strength is 100 times the values used by the other browsers. Basically IE used percentage (eg 0% to 100%) whereas the other browsers used a value between 0 and 1.