View Single Post
Old 01-02-2013, 03:47 PM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,191
Thanks: 217
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
text fader works in all browsers except chrome

Hi here is the text fader that i am using, it works in all other browsers just fine but in chrome it does not work right.

In chrome the page loads and you see the text, but once it fades, its gone and does not come back.


I call it in the header like this

Code:
<script type="text/javascript" src="textrotate.js"></script>
and then display it in the file like this


Code:
<!-- added for text rotator -->

<noscript>
<div style="font-size:small;margin:0px 10px 0px 10px;">
We can customize a plan just for your particular needs...<br /><br />Also it appears you have javascript disabled or your browser does not support JavaScript!
</div>
</noscript> 

<div style="font-size:small;margin:0px 10px 0px 10px;" id="quotes"></div>

<script type="text/javascript">
rotateText(document.getElementById("quotes"), "quotes");
</script>

<!-- end text rotator -->

Here is the js file.

Code:
// <![CDATA[

function rotateText(el, textGroup) 
{
  setOpacity(el, 0);

  //grab current text
  var sametext = document.getElementById('quotes').innerHTML;

   //get new text
   var group = rotateText.texts[textGroup];
   var t = group[Math.round(Math.random() * (group.length - 1))];

   //if they are the same then get another one
   if(sametext == t)
    {  
     var group = rotateText.texts[textGroup];
     var t = group[Math.floor(Math.random() * (group.length - 1))];
      }//close if

  el.innerHTML = t;
  unfadeText(el, textGroup);

}//close function rotateText

rotateText.texts = 
{
  quotes: [
    "text1...",
    "text2...",
    "text3...",
    "text4...",
    "text5...",
    "text6...",
    "text7...",
    "text8..."
        ]
};

function setOpacity(el, value) 
{
  el.style.opacity = value / 100;
  el.style.filter = "alpha(opacity=" + value + ")";
}

function unfadeText(el, tg) 
{
  var v = (el.style.opacity * 100) + 1;
  if(v > 100) {
    setOpacity(el, 100);
    setTimeout(bundleFunction(null, fadeText, [el, tg]), 10000);  /* number of seconds, this is 10 sec */
    return;
  }
  setOpacity(el, v);
  setTimeout(bundleFunction(null, unfadeText, [el, tg]), 10);
}

function fadeText(el, tg) 
{
  var fadt = (el.style.opacity * 100) - 1;

  if(!fadt > 0) 
   {
    setOpacity(el, 0);
    rotateText(el, tg);
    //or... setTimeout(bundleFunction(null, rotateText, [el, tg]), NUMBER);
    return;
  }
setOpacity(el, fadt);
setTimeout(bundleFunction(null, fadeText, [el, tg]), 10);
}//close function fadeText

function bundleFunction(context, func, args) 
{
  context = context || null;
  if(typeof func == "string")
  {
    if(context)
    {
    func = context[func];
    }//close if
  }//close if

  if(!args)
  {
   args = [];
     }else if(!(args instanceof Array))
       {
      args = [args];
       }//close elseif

return function() 
 {
 return func.apply(context, args);
  }//close return function

}//close function bundleFunction

// ]]>

Last edited by durangod; 01-03-2013 at 02:16 AM..
durangod is offline   Reply With Quote