Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top