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

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top