Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Mon Nov 23, 2009 9:28 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ]  Bookmark and Share
Author Message
 Post subject: Opacity - Fading Up Text (Simple Script)
PostPosted: Mon Aug 17, 2009 7:20 pm 
Offline

Joined: Thu Aug 28, 2008 10:56 pm
Posts: 6
Hello: I'm trying to get text to fade up in opacity. Using a simple model script like this (below), I can get the text to fade down in opacity but not up. I would appreciate help. Thank-you. MLR
===================================================
<script type="text/javascript">
function onloadMLR()
{
setInterval("startFadeMLR()",5);
}
function startFadeMLR()
{
var currentOpacityMLR=document.getElementById("textMLR").style.opacity;
if (currentOpacityMLR<1)
{
document.getElementById("textMLR").style.opacity+=0.02;
}
}
</script>
</head>
<body onload="onloadMLR()">
<div style="opacity : 0;" id="textMLR">TEXT</div>


Top
 Profile  
 
 Post subject: Re: Opacity - Fading Up Text (Simple Script)
PostPosted: Tue Aug 18, 2009 1:40 am 
Offline

Joined: Thu Aug 28, 2008 10:56 pm
Posts: 6
I received a resolving answer from Jeff (user name: BabyJeffy). Thank-You, MLR ...
Code:
<script type="text/javascript">
var FADE_FRAME_RATE = 5; // milliseconds between frames
var FADE_FRAME_AMOUNT = 0.002; // the amount of opacity to increase each frame
var timerHandle;

function onloadMLR()
   {
      timerHandle = setInterval("startFadeMLR('textMLR')", FADE_FRAME_RATE);
   }

function startFadeMLR(nodeId)
   {
         var nodeToFade = document.getElementById(nodeId);
         if (nodeToFade.style.opacity == '')
      {                              // if opacity is not set then stop everything
         nodeToFade.style.opacity = 1;
      }
         var currentOpacityMLR = parseFloat(nodeToFade.style.opacity);
         if (currentOpacityMLR < 1)
      {
         nodeToFade.style.opacity = currentOpacityMLR + FADE_FRAME_AMOUNT;
      }
         else
      {
         nodeToFade.style.opacity = 1;
         clearTimeout(timerHandle);
         timerHandle = null;
      }
   }

window.onload = onloadMLR;

</script>
</head>

<body>

<h6>Test Fade Up Opacity</h6>
<p style="opacity:0.0;" id="textMLR">Lorem ipsum dolor sit amet.</p>


Top
 Profile  
 
 Post subject: Re: Opacity - Fading Up Text (Simple Script)
PostPosted: Tue Aug 18, 2009 1:42 am 
Offline

Joined: Thu Aug 28, 2008 10:56 pm
Posts: 6
Where I went wrong ... The left of the line (document.getElementById("textMLR").style.opacity) returns a string. The += will perform a string concatenation (because the first part is a string). The reason it would work with -= is that it will always try to convert the left to a number.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley