views:

128

answers:

2

Hi there. I have a simple href that calls a javascript function that makes a div hidden and shows another one instead of it. Then I'm using javascript to put in some nice fade-in effect. It works fine in Firefox and chrome. On IE I had to use width: 100% to make it work. And tho it's working now, it totally ruins my font type. Here's the code:

Javascript:

function switch() 
{


if(document.getElementById("div1").style.visibility == "visible")
 {
  document.getElementById("div1").style.visibility = "hidden";
  document.getElementById("div1").style.display = "none";
  document.getElementById("div2").style.visibility = "visible";
  document.getElementById("div2").style.display = "block";  
  initfade('div2');
 }
 else
 {
  document.getElementById("div2").style.visibility = "hidden";
  document.getElementById("div2").style.display = "none";
  document.getElementById("div1").style.visibility = "visible";
  document.getElementById("div1").style.display = "block";   
  initfade('div1');
 }
 }

function initfade(img) {

   imageId = img;
   image = document.getElementById(imageId);
   setOpacity(image, 0);
   image.style.visibility = 'visible';
   fadeIn(imageId,0);
 }
 function setOpacity(obj, opacity) {
   opacity = (opacity == 100)?99.999:opacity;

   // IE/Win
   obj.style.filter = "alpha(opacity="+opacity+")";

   // Safari<1.2, Konqueror
   obj.style.KHTMLOpacity = opacity/100;

   // Older Mozilla and Firefox
   obj.style.MozOpacity = opacity/100;

   // Safari 1.2, newer Firefox and Mozilla, CSS3
   obj.style.opacity = opacity/100;
  }

  function fadeIn(objId,opacity) {
     if (document.getElementById) {
        obj = document.getElementById(objId);
        if (opacity <= 100) {
            setOpacity(obj, opacity);
            opacity += 30;
            window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
         }
         if (opacity > 100) {
      setOpacity(obj, 100);
         }    
      }
   }

HTML:

<div id="div1" class="theStyle2_visible" style="visibility: visible;">
    <div id="normal" class="normal">
       <p>Example Text</p>
    </div>
</div>
<div id="div2" class="theStyle2" >
    <div id="normal" class="normal">
       <p>Example Text</p>
    </div>
</div>
<a id="switchlink" href="javascript:switch();">Switch</a>

CSS:

    .theStyle2 { 
 visibility: hidden;
 width: 100%;
 display: none;
 z-index: -1; 
     }
     .theStyle2_visible {
 width: 100%; 
     }
     #normal{
        font: 0.9em  arial;
        font-weight:400;
        line-height: 20px;
 text-align:justify;
     }

I have no idea what I'm doing wrong and how to fix it or if this is just a bug but I've tried like a million things and nothing seems to work. Any good soul wanna help me? please!

thanks.

EDIT: Live link here: www.optimizer.pt/fade If you test it on firefox and IE you'll see what I mean. I have no idea what's going on...

A: 

Not sure what the problem is, but when you say "ruins my font type": Can you give the element that gets faded a background color? That often helps.

Pekka
i already tried that but it didnt help. i dont really know what the problem is also. It's something really weird. That's I also have no clue how to solve it...
A: 

anyone? I still haven't been able to solve this... I know it has something to do with IE's filters. I've tried to reproduce the filters on javascript after the fade-in effect but couldn't do it also...