Domanda

I have the following code:

<div id='icro' style="position:relative;left:-133px;float: left;top:-60px;opacity:0;">icro</div>
<script>
  var showicroDelay;
  showicro();
  function showicro() {
    document.getElementById('icro').style.opacity=parseInt(document.getElementById('icro').style.opacity) +.05;
    showicroDelay=setTimeout(showicro, 1);
    if (document.getElementById('icro').style.opacity==1) {
      clearTimeout(showicroDelay);
    }
  }
</script>

Can someone spot my mistake? I used basically the same code for moving an element and it worked flawlessly! As of now, it only does it once, as in the opacity gets set to 0.05.

Thanks

È stato utile?

Soluzione

You are using parseInt when you should be using parseFloat since opacity values are between 0 and 1.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top